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.
Since we do a lot of this in Rego, I was curious to learn what the cost of that was, and if it was possible to do better. I identified the two main costs as these:
handleErr
wrapper allocating in each iteration, even though the normal condition is to not handle an errorbiunify
callback function literal leaking to the heap in each iteration, with an high cost associated for such a simple one-liner function. While it wasn't possible to change that (as it referenced the outer scope) it was possible to inline the whole biunify flow for the array iteration case, as that turned out to be quite simple when stepped through with a debugger.Ideally we'd be able to inline iteation over sets and objects too, but that's much more complex (see comment in code), so I left that for the future.
The numbers benchmarked are in the PR, so take a look there. The array iteration case is quite the improvement!
For reference, this amounts to about 2 million allocations less in the
regal lint bundle
benchmark, and a noticeable improvement in evaluation time.