fix: cel env after cache lookup#161
Conversation
RunExpressionContext built the full CEL env option set (GetCelEnv, including kubernetes.Library() and one cel.Variable per env key) on every call before consulting the compiled-program cache, then discarded it on cache hits, since cel.NewEnv only runs to compile a new program. This made GetCelEnv (notably kubernetes.Library()) the dominant lifetime allocator on the CEL path: in a production config-db heap profile it accounted for ~38% of alloc_space, called on every evaluation. Move the cache lookup ahead of GetCelEnv and construct env options only inside the cache-miss branch where cel.NewEnv actually consumes them. Cache-hit steady state now skips GetCelEnv entirely. Behavior is unchanged: the cached cel.Program already carries its variable bindings and Eval still receives the serialized data.
Add BenchmarkRunExpressionContext (cacheHit smallEnv/largeEnv) guarding the cache-hit steady state where GetCelEnv must not run, modeled on the production config-item env shape with no duty/config-db dependencies. Wire it into the benchmark workflow alongside BenchmarkSerialize: base-vs-head benchstat, a report comment posted to the PR, and the existing 5% regression gate. Copy the new bench file into the base worktree so both runs execute the same suite, only the implementation under test differing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Walkthrough
ChangesCEL Cache-Hit Optimization and Benchmarking
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
BenchstatBase: 6 improvement(s)
Full benchstat output |
Summary by CodeRabbit
Tests
Refactor
Chores