GeezerVison is showing github.com — perf: optimize parsing in Connection API by toddlipcon · Pull Request #3800 · googleapis/java-spanner
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Conversation
toddlipcon
commented
Apr 8, 2025
•
edited by olavloite
Loading
Uh oh!
There was an error while loading. Please reload this page.
This fixes a performance bottleneck I noticed while profiling pgadapter under a TPCC workload.
With change
Benchmark Mode Cnt Score Error Units
StatementParserBenchmark.isQueryTest thrpt 5 475330.395 ± 2522.511 ops/s
StatementParserBenchmark.longDmlTest thrpt 5 3611.682 ± 58.704 ops/s
StatementParserBenchmark.longQueryTest thrpt 5 5015.354 ± 8.138 ops/s
Main
Benchmark Mode Cnt Score Error Units
StatementParserBenchmark.isQueryTest thrpt 5 338079.227 ± 26995.410 ops/s
StatementParserBenchmark.longDmlTest thrpt 5 1153.123 ± 5.604 ops/s
StatementParserBenchmark.longQueryTest thrpt 5 2011.550 ± 72.433 ops/s
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Also fixes the pom to run the annotation processor so that
mvn -Pbenchmark actually is able to run benchmarks.
I found this was taking ~25% of the CPU of pgadapter when running
the TPCC benchmark loader, which seems to generate very large DMLs.
Previously, it would call split() over the whole string with
a limit. Now, it uses Guava's lazy splitter so that it doesn't
have to copy the remainder of the string following the second
match.
For whatever reason, it seems like the previous implementation
was doing something much more expensive than just copying the
tail. For 100kb long query text, this new implementation is
1600x faster. For short queries it's only a few times faster.
Before:
Benchmark Mode Cnt Score Error Units
StatementParserBenchmark.isQueryTest thrpt 5 1461962.835 ± 340237.573 ops/s
StatementParserBenchmark.longQueryTest thrpt 5 2873.150 ± 490.611 ops/s
After:
Benchmark Mode Cnt Score Error Units
StatementParserBenchmark.isQueryTest thrpt 5 4765215.378 ± 132661.232 ops/s
StatementParserBenchmark.longQueryTest thrpt 5 4671884.683 ± 486566.506 ops/s
The `supportsExplain()` method did not actually do anything useful and
returned the wrong result. The reason that it was not useful is that:
1. Parsers that do support the EXPLAIN keyword handle these as client-side statements.
This means that they never go into the isQuery() method.
2. Parsers that do not support the EXPLAIN keyword cannot do anything with it anyways.
Reviewers
2 more reviewers
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Labels
api: spanner
Issues related to the googleapis/java-spanner API.
size: m
Pull request size is medium.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|