Skip to content

Reuse CelExpressionFlatImpl evaluation state across non-concurrent Evaluate calls. - #2299

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_988498326
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_988498326

Conversation

@copybara-service

Copy link
Copy Markdown

Reuse CelExpressionFlatImpl evaluation state across non-concurrent Evaluate calls.

  • CelExpressionFlatImpl now owns a FlatExpressionEvaluatorState
    (cached_state_) that Evaluate(activation, arena) reuses when it is not
    already in use (claimed via std::atomic<bool> cached_state_in_use_).
    Concurrent callers fall back to the existing per-call InitializeState
    path, so thread safety is unchanged.
  • This avoids allocating/freeing the evaluator state (value stack,
    comprehension slots, iterator stack) on every evaluation.
  • FlatExpressionEvaluatorState gains a dirty_ flag so Reset() is a no-op
    when nothing was evaluated, plus SetArena() so the cached state can be
    bound to the caller's arena for the duration of one call.
  • Removes the redundant state->state().Reset() in Trace.

…aluate calls.

- `CelExpressionFlatImpl` now owns a `FlatExpressionEvaluatorState`
  (`cached_state_`) that `Evaluate(activation, arena)` reuses when it is not
  already in use (claimed via `std::atomic<bool> cached_state_in_use_`).
  Concurrent callers fall back to the existing per-call `InitializeState`
  path, so thread safety is unchanged.
- This avoids allocating/freeing the evaluator state (value stack,
  comprehension slots, iterator stack) on every evaluation.
- `FlatExpressionEvaluatorState` gains a `dirty_` flag so `Reset()` is a no-op
  when nothing was evaluated, plus `SetArena()` so the cached state can be
  bound to the caller's arena for the duration of one call.
- Removes the redundant `state->state().Reset()` in `Trace`.

PiperOrigin-RevId: 988498326
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.

0 participants