Reduce HQL parser cold-start allocation - #4337
Open
gregjotau wants to merge 2 commits into
Open
Conversation
Factor overlapping function-path and predicate grammar alternatives to reduce ANTLR adaptive prediction while preserving query rendering and transformation behavior. Add a single-shot JMH benchmark for the cold parse path. Closes spring-projects#4326 Signed-off-by: arai <arailymkaliyeva.m@gmail.com>
Retain only the function-path and binary-predicate grammar changes that account for the measured cold-start improvement. Add EQL and JPQL controls, SLL fast-path regression coverage, and focused binary-predicate tests. Signed-off-by: Greg Taube <gregjotau@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Supersedes #4327, originally submitted by @araiprof. The original commit and authorship are preserved in this branch; this follow-up narrows the production change and adds comparative controls and regression coverage.
Closes #4326.
The generated HQL parser spends a disproportionate amount of its first parse in ANTLR adaptive prediction. Two grammar decisions have overlapping expression prefixes: function-backed paths and binary predicates. Left-factoring those alternatives reduces the cold ATN/DFA work without changing the accepted query forms.
The patch deliberately drops the original PR's IN, BETWEEN, LIKE, and EXISTS refactors. A 10-fork ablation showed that function-path plus binary-predicate factoring retains effectively the entire improvement with less parser-tree and visitor churn:
mainJMH 1.37, JDK 26.0.2.1, 10 fresh forks, no warmup, one
SingleShotTimeinvocation per fork,-prof gc; errors are 99.9% confidence intervals. A final run of the submitted code measured 179.589 ± 6.957 ms/op and 177.204 MB/op.EQL and JPQL measurements using the same query are included as controls. The final run measured EQL at 109.209 ± 8.067 ms/op and 87.986 MB/op, and JPQL at 103.351 ± 7.175 ms/op and 76.213 MB/op. Instrumenting the upstream query-test corpus found no equivalent valid-query fallback in those grammars, so this PR does not change them.
The function-path regression test also verifies the causal behavior directly: affected valid HQL creates two parser instances on current
mainbecause SLL falls back to LL, and one parser instance with this change.In an external Spring Boot 4.2.0-M1 application, 10 controlled cold starts improved from 15.2566 s to 13.7356 s on average (-1.521 s, -9.97%); repository initialization improved from 4.161 s to 2.848 s (-31.55%).
The HQL grammar is already compiled into Java at build time. The remaining cost is generated parser initialization and runtime adaptive prediction, so simplifying the ambiguous decisions is the applicable fix rather than moving application work into AOT processing.
Validation:
PgVectorIntegrationTestsfailed because Docker is unavailable on the test host.