Skip to content

Reduce HQL parser cold-start allocation - #4337

Open
gregjotau wants to merge 2 commits into
spring-projects:mainfrom
gregjotau:codex/hql-parser-cold-start
Open

Reduce HQL parser cold-start allocation#4337
gregjotau wants to merge 2 commits into
spring-projects:mainfrom
gregjotau:codex/hql-parser-cold-start

Conversation

@gregjotau

Copy link
Copy Markdown

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:

Variant Cold parse Allocation
Current main 405.980 ± 26.846 ms/op 544.984 MB/op
Function paths only 336.987 ± 61.112 ms/op 233.410 MB/op
Function paths + binary predicates (this PR) 191.533 ± 12.861 ms/op 177.225 MB/op
Full original patch 197.995 ± 13.436 ms/op 176.731 MB/op

JMH 1.37, JDK 26.0.2.1, 10 fresh forks, no warmup, one SingleShotTime invocation 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 main because 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:

  • Focused renderer, transformer, enhancer, SLL fast-path, and order-expression tests pass in all four Maven executions (438 tests per execution, zero failures).
  • All 16 retained binary predicate spellings have focused rendering coverage.
  • The full module run reached 2,631 tests with no assertion failures related to this change; only the 14 Testcontainers-backed PgVectorIntegrationTests failed because Docker is unavailable on the test host.

araiprof and others added 2 commits August 29, 2026 17:29
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce HQL parser cold-start allocations caused by ambiguous grammar alternatives

3 participants