Add runtime cost tracking for string extension functions#1288
Open
qq96932100 wants to merge 1 commit intogoogle:masterfrom
Open
Add runtime cost tracking for string extension functions#1288qq96932100 wants to merge 1 commit intogoogle:masterfrom
qq96932100 wants to merge 1 commit intogoogle:masterfrom
Conversation
stringLib.ProgramOptions() returns empty, so string extension calls get a flat runtime cost of 1 regardless of input size. The lists and regex extensions already register cost trackers; this adds the same for string overloads.
Collaborator
|
/gcbrun |
| func (*stringLib) ProgramOptions() []cel.ProgramOption { | ||
| return []cel.ProgramOption{} | ||
| func (lib *stringLib) ProgramOptions() []cel.ProgramOption { | ||
| trackers := []interpreter.CostTrackerOption{ |
Collaborator
There was a problem hiding this comment.
Even though the functions are introduced at a specific version, changes in cost tracking also need to be versioned, so you'll have to make the version check >= 4 for all cost changes.
| // ProgramOptions implements the Library interface method. | ||
| func (*stringLib) ProgramOptions() []cel.ProgramOption { | ||
| return []cel.ProgramOption{} | ||
| func (lib *stringLib) ProgramOptions() []cel.ProgramOption { |
Collaborator
There was a problem hiding this comment.
Note, it's important to introduce cost calculations for the checked expression as well, otherwise the runtime cost value may far exceed the expected cost
Collaborator
|
@qq96932100 thanks for the contributions! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stringLib.ProgramOptions()returns an empty slice, so string extension calls (replace, split, join, indexOf, etc.) all get charged a flat runtime cost of 1 incostCall()regardless of input size. This makesCostLimitineffective for these operations — chainedreplacecalls can produce exponentially growing output while staying under the cost budget.The lists and regex extensions already register proper cost trackers. This adds the same for string extension overloads, version-gated to match function availability.