Cache compiled programs by serialized rule message#452
Closed
snuderl wants to merge 1 commit intobufbuild:mainfrom
Closed
Cache compiled programs by serialized rule message#452snuderl wants to merge 1 commit intobufbuild:mainfrom
snuderl wants to merge 1 commit intobufbuild:mainfrom
Conversation
Fields with identical resolved rules (same rule type + same values, e.g. multiple fields sharing the same predefined constraint like an evm_hash pattern) currently re-create their CompiledProgram list independently, even though the resulting programs are equivalent. Add a static ConcurrentHashMap keyed by the serialized rule message bytes that caches the built List<CompiledProgram>. On hit we short-circuit the rebuild; on miss we populate it at the end of compile(). In a workload with 14 descriptor types and 19 fields sharing 2 predefined rules, this reduced warmup time from ~58ms to ~3.6ms.
2 tasks
Contributor
Author
|
Superseded by #453, which achieves the same reuse by caching the compiled program in the existing descriptor-keyed cache (matching protovalidate-go's design) instead of adding a second bytes-keyed cache. |
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.
Summary
Fields with identical resolved rules (same rule type + same values — e.g. multiple fields sharing the same predefined constraint such as an
evm_hashpattern) currently rebuild theirList<CompiledProgram>from scratch every time, even though the resulting programs are equivalent.This PR adds a static
ConcurrentHashMapinRuleCachekeyed by the serialized rule message bytes. On hit,compile()returns the cached list directly; on miss, it falls through to the existing build path and populates the cache with the result.In a workload with 14 descriptor types and 19 fields sharing 2 predefined rules, warmup time dropped from ~58ms to ~3.6ms.
Note: this is independent of the cache-key fix in #451 — the two help different scenarios (AST reuse across fields sharing a rule field descriptor vs. program reuse across fields with identical resolved rule values) and can be merged in either order.
Test plan
./gradlew test)