Skip to content

Support evaluating precompiled AST (evaluateAst) #93

@Zhreyu

Description

@Zhreyu

Hi,

We’re using cel-js in a system where CEL expressions are compiled and stored
as AST (serialized JSON) in a database.

Currently, Environment.evaluate() requires a source string and internally
re-parses it on every call. This prevents reuse of precompiled ASTs and leads
to repeated parsing overhead.

Would it be possible to expose an API like:

evaluateAst(ast, context)

This would allow:

  • Reusing compiled expressions across requests
  • Avoiding repeated parsing
  • Better performance in high-frequency evaluation scenarios

Happy to contribute if this aligns with the project direction.

Thanks!

PS: we're aware of parse() for in-memory reuse. Our use case requires persisting the compiled AST to a database and reloading it in a different process/request without re-parsing. The current AST structure contains function references (#meta.evaluate) that aren't JSON-serializable, so we can't round-trip through storage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions