Lint performance Rego refactor#1857
Merged
anderseknert merged 1 commit intoopen-policy-agent:mainfrom Feb 9, 2026
Merged
Conversation
srenatus
reviewed
Feb 9, 2026
| "boolean": `[%v]`, | ||
| }[part.type], | ||
| [part.value], | ||
| ) |
Member
Author
There was a problem hiding this comment.
Lol, yes, but so much cheaper than branching with custom functions. Maybe one day it won't be 🥲
srenatus
approved these changes
Feb 9, 2026
- Rewrite `walk` calls that needed the `path` from the walk so that they no longer do. This is by far the most impactful change here, accounting for 90% of the reduces allocs - Inline and remove a few custom functions that only had a single dependent - Avoid `count(x) == 0` and `count(x) > 0` in favor of `x == []` and `x != []` (or `""`, `set()`, etc) when the type is known - Rewrite some `count([x | some x in y]) == z` constructs to instead use `every` - Avoid costly path in rule-length check (counting comments) if the rule length wasn't exceeded to begin with - Replace `some i, x in y; i > 0` with `some x in array.slice(y, 1, max)` to avoid repeated gt call - Rewrite hot path function `ref_to_string` to allocate much less by calling less custom functions, and replacing an `else` condition with a map lookup Reducing almost 1/4 of all memory (B/op) previously allocated! **BenchmarkRegalLintingItselfPrepareOnce** ``` 486491514 ns/op 1906786789 B/op 45640947 allocs/op // OPA v1.13.1 + fixes 420959403 ns/op 1534395760 B/op 36917131 allocs/op // Performance refactor ``` Signed-off-by: Anders Eknert <anders.eknert@apple.com>
81e2051 to
47f6242
Compare
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.
walkcalls that needed thepathfrom the walk so that they no longer do. This is by far the most impactful change here, accounting for 90% of the reduces allocscount(x) == 0andcount(x) > 0in favor ofx == []andx != [](or"",set(), etc) when the type is knowncount([x | some x in y]) == zconstructs to instead useeverysome i, x in y; i > 0withsome x in array.slice(y, 1, max)to avoid repeated gt callref_to_stringto allocate much less by calling less custom functions, and replacing anelsecondition with a map lookupReducing almost 1/4 of all memory (B/op) previously allocated!
BenchmarkRegalLintingItselfPrepareOnce