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

feature: provide operator controls for bounded complexity #37

Closed
kyessenov opened this issue Aug 23, 2019 · 2 comments · Fixed by #39
Closed

feature: provide operator controls for bounded complexity #37

kyessenov opened this issue Aug 23, 2019 · 2 comments · Fixed by #39
Assignees

Comments

@kyessenov
Copy link
Collaborator

Add controls for tuning the evaluation cost of the runtime:
Memory
Most operations are have no additional allocation costs beyond the memory required to represent the value within the runtime. There are a couple of exceptions to this rule:

Type conversion functions can result in fixed-size allocations, e.g. string to timestamp.
The re2-based matches performs its own allocations when compiling the input regex pattern.
RE2 provides its own internal control for the limits of the regex.
The + operator supports string / list concat where the memory cost is variable with the size of the input.
CPU
The majority of CEL functions and macros are O(1) or O(n), with a couple of exceptions.

The re2-based matches is linear, but with a high-constant factor.
The in operator can be super-linear when testing for a string value in a non-literal list.
The comprehension macros all, exists, filter, map support bounded iteration and nesting.

Tuning
In many cases, the matches function is eschewed in favor of the simpler startsWith, endsWith, and contains functions.

The in operator can be linted to ensure that a list or map literal appears on the right-hand side of the expression, as this special case is treated as a set membership test rather than as a per-element comparison of the list elements.

Some environments disable the + operator due to its inclusion of string and list overloads. I think that CEL might need to deprecate the concatenation overloads in the near-term in favor of a concat function which can be expressly removed from the environment.

Most of the performance critical use cases for CEL disable macros entirely, though there are a couple of linear-time macros currently supported in Istio.

With the above recommendations, you'll have fixed allocation size operations that run in linear or sub-linear time. If you want to support in and +, I would recommend lint checks on the AST to ensure that they are used in a performance manner (in) or with limited frequency (+).

@htuch
Copy link

htuch commented Oct 24, 2019

@kyessenov are we going to be able to have these complexity controls on the Envoy RBAC filter now?

@kyessenov
Copy link
Collaborator Author

Yeah, need another follow-up to get past -Wunused-parameters build problem. Adding copts = ["-Wno-unused-parameters"] doesn't seem to help.

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 a pull request may close this issue.

2 participants