Fix cache key mismatch in RuleCache.compileRule#451
Merged
pkwarren merged 3 commits intobufbuild:mainfrom Apr 23, 2026
Merged
Conversation
The descriptorMap lookup at the top of compileRule() used fieldDescriptor (the user's field), but the corresponding store at the bottom uses ruleFieldDesc (the rule field, e.g. StringRules.pattern). The read therefore always missed, and cached CelRules were never reused across different user fields that share the same predefined rule. Use ruleFieldDesc for the lookup so it matches the store.
This was referenced Apr 23, 2026
Member
|
Thank you for the contribution. The fix looks correct to me - I've merged the latest changes from main which resolve an issue with PRs raised from forks although builds may still be rate limited. Can you sign the CLA? |
pkwarren
approved these changes
Apr 23, 2026
Member
|
Wiring up a small benchmark harness - verified the fix: |
pkwarren
added a commit
that referenced
this pull request
Apr 23, 2026
In order to verify performance fixes (like #451 and #454), it would be helpful to be able to write a JMH benchmark and quickly measure the impact. This adds a benchmark module to the Gradle build. CI only verifies the build of the benchmarks. Added a README showing how to add benchmarks and measure improvements locally. Instead of outputting JSON or other format, created a jq script to roughly print out output similar to benchstat for Go.
pkwarren
added a commit
that referenced
this pull request
Apr 23, 2026
In order to verify performance fixes (like #451 and #454), it would be helpful to be able to write a JMH benchmark and quickly measure the impact. This adds a benchmark module to the Gradle build. CI only verifies the build of the benchmarks. Added a README showing how to add benchmarks and measure improvements locally. Instead of outputting JSON or other format, created a jq script to roughly print out output similar to benchstat for Go.
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
RuleCache.compileRule()stores entries indescriptorMapkeyed byruleFieldDesc(the rule field, e.g.StringRules.pattern), but the lookup at the top of the method usesfieldDescriptor(the user's field being validated).The read key and write key never agree, so cached
CelRulelists are never reused across different user fields that share the same predefined rule — every call falls through and re-builds the AST.This PR changes the lookup to use
ruleFieldDescso it matches the store.Test plan
./gradlew test)