spring-projects / spring-projects/spring-data-commons
Avoid allocations when rewriting queries without value expressions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Spring Data Commons 4.2.0-SNAPSHOT constructs a mutable expression map, a rewritten query string, and a second quotation map for every query passed to ValueExpressionQueryRewriter, even when the query contains no value expression. Ordinary repository queries commonly take this path.
A no-expression fast path can retain the initial matcher and quotation-map construction, then reuse the original query string and an immutable empty parameter map when the first matcher search finds nothing. This preserves unbalanced-quotation validation and quotation metadata.
JMH on JDK 26, with three forks and the GC profiler, measured the ordinary-query path at 608.007 B/op before and 232.004 B/op after the fast path, a deterministic 61.8% allocation reduction. Independent negative controls were unchanged to measurement precision: quoted expression-like text remained 1,368 B/op and an actual expression remained 9,576 B/op.
A separate 729-query fresh-JVM batch used 30 forks, no warmup, SingleShotTime, and 99.9% confidence intervals. It improved from 7.577 ± 0.845 ms and 1.422 MB to 5.349 ± 0.201 ms and 1.008 MB, reducing both time and allocation by about 29%.
The proposed change includes focused tests for input-string reuse, retained quotation information, unbalanced quotations, real expressions, and expression-like text inside quotes, plus a permanent JMH benchmark.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ValueExpressionQueryRewriter and trace the first matcher search, quotation validation, and parameter-map handling. Add the no-expression path while preserving input-string reuse and quotation metadata, then verify focused tests for quoted text, unbalanced quotations, and real expressions alongside the permanent JMH benchmark.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100