perf: reduce allocation in expression binding and template parsing#297
Merged
Conversation
Object-expression binding allocated a list and a name-keyed map for every bound value, although single-column expressions, the vast majority, only need the one value. A reusable collector now binds the scalar directly and materializes the map only when a second column appears; version-aware binding locates the version column without stream machinery. Template fragment lists are a pure function of the raw template string, and interpolated values travel separately as placeholders, so parsed fragments are now cached per template shape in a bounded LRU cache. Allocation per operation drops a further 6-9% on the by-id read, read-modify-update, and create-then-amend workloads and 5% on the dynamically assembled projection, bringing the cumulative reduction since the start of the build-path work to 38-45% and 17% respectively. Refs #294
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.
Part of #294 (the issue stays open for the remaining tail).
What
Follow-up to #296, targeting the two allocation sites JFR ranked highest after that merge.
Expression binding.
bindObjectExpressionallocated anArrayListplus a name-keyedLinkedHashMapfor every bound value, although single-column expressions, the vast majority, only need the one value. A reusable collector binds the scalar directly and materializes the map only when a second column appears (only multi-column expressions need it); the multi-values list is likewise created on demand. Version-aware binding locates the version column with a plain loop.Template fragment parsing. Fragment lists are a pure function of the raw template string; interpolated values travel separately as
\0placeholders, so the key space is bounded by the application's distinct template shapes. Parsed fragments are now cached in a bounded LRU (shared immutable lists), in a package-private helper so nothing leaks into theTemplateBuilderinterface surface.Measured effect
JMH allocation profiler, per operation:
Precise counters on the by-id build phase: 4,131 → 3,693 B/op; the dynamically assembled projection's build: 6,682 → 5,796 B/op.
Testing
All suites green against their real databases: storm-core 2307 · H2 158 · SQLite 131 · PostgreSQL 178 · MySQL 175 · MariaDB 158, plus a full reactor test-compile. No API changes; binding semantics (including version-aware error paths and null-value comparison) are unchanged.