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
builtins: Speed up set unions #4980
builtins: Speed up set unions #4980
Conversation
2922ae1
to
91089c8
Compare
I'm going to add some correctness/regression tests, at the suggestion of @charlesdaniels. The tests will compare the behavior of |
I've split the |
9327d01
to
c06ced6
Compare
cc0c426
to
3d554b4
Compare
3d554b4
to
cc55914
Compare
cc55914
to
ac82c32
Compare
LGTM. In this case, inlining the union logic is cheap enough that the speedup is worth it. |
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
The compiler correctly handled the lexical scoping here, but changing the name makes it explicit for the humans reading that snippet as well. Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
ac82c32
to
28e3272
Compare
@tsandall Thanks for looking the PR over! I'll merge this in soon. |
This PR fixes a performance regression for the set
union
builtin, discovered in issue #4979.The original logic for the builtin did pairwise
Set.Union
calls between the input sets, resulting in a lot of wasted temporary Sets that were almost immediately discarded, and a lot of duplicated work. The updated builtin inlines the logic fromSet.Union
, so that only one pass is made across the incoming sets' members.In the included benchmarks, this provides a small, but significant improvement over using a pure-Rego comprehension to do the same job.
Fixes #4979
The 3x relevant benchmarks are shown below:
union
onmain
branchunion
on this PRBenchmarks
Benchmark of
union
onmain
branch:Benchmark of Pure Rego implementation:
Benchmark of
union
on this PR:Summary of Results
The benchmarks show that the PR is roughly 15-30% faster and has ~14% fewer allocations than the pure Rego solution. The resolution of these charts are blown out by the 10x10 and 250x250 cases, but still paint a strong picture of the performance changes nonetheless: