-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
My last PR for a while in the ongoing "reduce allocations in eval" quest. Motivated initially mostly to speed up `regal lint`, but most of the changes here positively impacts evaluation performance for most policies. The changes with the highest impact in this PR: * Use `sync.Pool`s to avoid the most costly allocations, includuing heavy `*eval` pointers created each time a child or closure scope is evaluated. * When tracing is disabled, avoid variable escaping to heap in `evalStep` function whose value is only read when tracing is enabled. * Save one allocation per iteration in `walkNoPath` by reusing an AST array instead of creating a new one for each call. Also a few minor fixes here and there which either fixed some correctness issue, or had a measurable (although minor) positive impact on performance. **regal lint bundle (main)** ``` BenchmarkRegalLintingItself-10 1 2015560750 ns/op 4335625360 B/op 83728460 allocs/op ``` **regal lint bundle (now)** ``` BenchmarkRegalLintingItself-10 1 1828754125 ns/op 3541027496 B/op 70080568 allocs/op ``` About 10% faster eval, with almost a gigabyte less memory allocated, and 13 million+ allocations less performed. Another topic discussed recently has been the cost of calling custom functions in hot paths. While this PR doesn't address that problem fully, the benefits of the change is still quite noticeable. A benchmark for that case specifically is also included in the PR, and the change compared to main as noted below: **main** ``` BenchmarkCustomFunctionInHotPath-10 55 18543908 ns/op 20821043 B/op 284611 allocs/op ``` **pr** ``` BenchmarkCustomFunctionInHotPath-10 73 16247587 ns/op 13048108 B/op 228406 allocs/op ``` It's worth noting however that this benchmark benefits "unfairly" by the improvements made in the `walkNoPath` function, and perhaps more so than custom function evaluation getting that much more efficient. Signed-off-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
563321d
commit b395bcd
Showing
17 changed files
with
8,123 additions
and
189 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.