Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add evaluation state dump utility type #74

Merged
merged 2 commits into from
Oct 16, 2024
Merged

lib: add evaluation state dump utility type #74

merged 2 commits into from
Oct 16, 2024

Conversation

efd6
Copy link
Collaborator

@efd6 efd6 commented Oct 15, 2024

This is intended to be used for whole-of-program debugging. If it works out here, it may be worth considering having an option in the CEL input to dump the eval state in the case of error. This cannot be on always since it is heavy, retaining the full state of all nodes during the evaluation.

Please take a look.

@efd6 efd6 self-assigned this Oct 15, 2024
@efd6 efd6 force-pushed the dumpstate branch 7 times, most recently from 3756e64 to 196e057 Compare October 15, 2024 05:16
@efd6 efd6 requested a review from a team October 15, 2024 05:18
@efd6 efd6 force-pushed the dumpstate branch 3 times, most recently from c259e6f to 1f4b6c2 Compare October 15, 2024 07:27
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dump output is interesting, and likely quite useful even during development as a pseudo step debugger. For a complex programs, I imagine the size of the EvalState can get large if (?) it is holding copies of the ref.Val at each eval (not sure about this though).

We can proceed with exposing this through mito, and then do some more testing in scenarios involving elastic/integrations.

prg, err := env.Program(ast)
var progOpts []cel.ProgramOption
if details {
progOpts = []cel.ProgramOption{cel.EvalOptions(cel.OptTrackState)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the memory implications of turning this on? Like how big does the EvalState become if say the program is processing a large XML response?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine this would be untenably large. The actual size would depend how many allocations were made to perform evaluations. In the worst case this would be the sum of all sizes for each evaluation node. In practice, I would imagine that this is mitigated by sharing between values when there has not been mutation or type conversion that requires a new allocation (e.g. []bytestring or map construction, though in the latter, the only allocation would be the shallow value). I think we need to experiment to get a completish picture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mitigated by sharing between values when there has not been mutation

That's what I hoping too, like a copy-on-write paradigm to achieve immutability while being memory efficient.

@efd6 efd6 merged commit b3efc2e into dev Oct 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants