Skip to content

Avoid allocations when rewriting queries without value expressions #3536

Description

@gregjotau

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions