Skip tautological compiled programs in RuleCache#460
Skip tautological compiled programs in RuleCache#460snuderl wants to merge 2 commits intobufbuild:mainfrom
Conversation
Mirrors protovalidate-go's ReduceResiduals: when a rule program evaluates to true (or empty string) using only the bound rules/rule variables, the expression is tautological and can be eliminated at compile time so it never runs during validation. Programs that reference unbound variables (this, now) raise CelEvaluationException and are kept as before.
Adds a 20-field float message with only 'gt' set on each field. The standard float.gt rule expands into five CEL programs; four of them short-circuit to '' using only the bound rules variable when neither 'lt' nor 'lte' is set. This benchmark targets the residual-reduction skip in RuleCache.
Benchmark resultsAdded a A/B run on the same machine, JDK 21, JMH defaults (3×2s warmup, 5×2s measurement, 2 forks, AverageTime mode). Baseline is The targeted benchmark drops ~40% in both time and per-op allocation (the four eliminated CEL programs are no longer evaluated and don't allocate intermediate result objects). Other benchmarks move within the typical run-to-run noise band for the default iteration budget — none of them have rule expressions that residualize to a constant, so no real change is expected there. |
|
Are there other rules that expand in the same way as gt/lt? |
Summary
ReduceResidualsoptimization inRuleCache: after compiling a rule's CEL program, we eagerly evaluate it with only therules/rulevariables bound.trueor""(the success values), it is tautological for this rule configuration and is dropped before being added to the per-field program list, so it never runs during validation.this(ornow) variables raiseCelEvaluationExceptionduring the probe; we swallow that and keep the program as before.This is a follow-up to #454, which performed a similar tautology check at the
MessageEvaluatorlevel.Test plan
./gradlew test— full unit + conformance suite passes locally.