Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

beldmian
Copy link
Contributor

While performing some performance testing for one of my projects, I saw that in case of creating many (a lot of) CEL programs in the same environment, creation of function bindings for them can take a significant percentage of CPU time, because they are being regenerated on every program creation, which, as I can see from code, feels really excessive. This PR suggest a way to perform calculation of bindings once for environment configuration and then reuse this bindings in program creation.

Probably, there also should be provided a way to change this behavior through options, let me know if that feels more acceptable with them.

Pull Requests Guidelines

See CONTRIBUTING.md for more details about when to create
a GitHub Pull Request and when other kinds of contributions or
consultation might be more desirable.

When creating a new pull request, please fork the repo and work within a
development branch.

Commit Messages

  • Most changes should be accompanied by tests.
  • Commit messages should explain why the changes were made.
Summary of change in 50 characters or less

Background on why the change is being made with additional detail on
consequences of the changes elsewhere in the code or to the general
functionality of the library. Multiple paragraphs may be used, but
please keep lines to 72 characters or less.

Reviews

  • Perform a self-review.
  • Make sure the Travis CI build passes.
  • Assign a reviewer once both the above have been completed.

Merging

  • If a CEL maintaner approves the change, it may be merged by the author if
    they have write access. Otherwise, the change will be merged by a maintainer.
  • Multiple commits should be squashed before merging.
  • Please append the line closes #<issue-num>: description in the merge message,
    if applicable.

@TristonianJones
Copy link
Collaborator

@beldmian ideally the programs would be cached rather than recreated. Is that perhaps an option?

@beldmian
Copy link
Contributor Author

@TristonianJones Programs are not serializable (at least in general way), which is needed to make them cached in my use case, the nearest to program thing serializable, as I can see, is checked expression of its AST.

@TristonianJones
Copy link
Collaborator

@beldmian I see, are you having to page in / out a lot of ASTs in the same environment?

@TristonianJones
Copy link
Collaborator

/gcbrun

@beldmian
Copy link
Contributor Author

@TristonianJones Yes, to be precise, I am precompiling a lot of cel expressions in one environment and then they are being shipped to another one (there they are being executed not really many times, but the execution should be fast and at the same time the consumption of resources should be small enough).

@beldmian beldmian force-pushed the improve-function-bindings-build branch from 9412cfb to 280ddaf Compare July 24, 2025 20:54
@beldmian beldmian requested a review from TristonianJones July 25, 2025 09:48
@TristonianJones
Copy link
Collaborator

/gcbrun

@TristonianJones TristonianJones merged commit fb02c9a into google:master Jul 25, 2025
2 checks passed
@TristonianJones
Copy link
Collaborator

@beldmian thanks for the contribution!

renevo pushed a commit to Blizzard/cel-go that referenced this pull request Sep 12, 2025
* Init function bindings on environment init

* Move calculation of function bindings under sync.Once call in new program creation
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.

2 participants