Skip to content

Conversation

@Krishanx92
Copy link
Contributor

@Krishanx92 Krishanx92 commented Jan 27, 2026

Purpose

Explain why this feature or fix is required. Describe the underlying problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.

Goals

Describe what solutions this feature or fix introduces to address the problems outlined above.

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI. Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Summary by CodeRabbit

  • Chores
    • Optimized policy evaluation performance through improved memory management and reduced memory allocations during condition evaluation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

The change optimizes memory management in the CEL evaluator by introducing sync.Pool instances to reuse evaluation context maps (evalCtx, requestCtx, responseCtx) and a pre-allocated emptyHeadersMap. Both EvaluateRequestCondition and EvaluateResponseCondition now allocate pooled maps instead of constructing inline contexts, with proper cleanup to prevent memory leaks.

Changes

Cohort / File(s) Summary
CEL Evaluator Memory Optimization
gateway/policy-engine/internal/pkg/cel/evaluator.go
Added three sync.Pool instances for context map reuse; replaced inline map construction with pooled allocations in EvaluateRequestCondition and EvaluateResponseCondition; introduced emptyHeadersMap for headers optimization; added map cleanup logic to return pooled structures after evaluation

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Pooling maps with mighty care,
No allocations floating in the air,
CEL contexts dance and reuse with grace,
Memory leaks? Not in this place!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is entirely template boilerplate with no substantive content filled in; all sections contain only placeholder text rather than actual implementation details, justification, or test information. Complete all required sections: explain the performance issue, describe the sync.Pool optimization approach, include code coverage details, security verification status, and test environment information.
Title check ❓ Inconclusive The title 'Fix perf issue' is vague and generic, using non-descriptive terms that don't convey specific information about which performance issue or what optimization was implemented. Replace with a more specific title that describes the actual optimization, e.g., 'Optimize CEL evaluator with sync.Pool for context reuse' to clarify the performance improvement.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant