Reuse scratch space for Sabre best-swap choice #10783
Merged
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.
Summary
This re-uses the same growable scratch space for storing the temporary swaps for each choice. This particular space typically needed to grow several times for each swap choice, which was taking up a non-negligible amount of the time we spent in Rust space, especially for large circuits on big coupling maps.
Details and comments
This is a super simple change, but drastically reduces the number of allocations / re-allocations we have to make during the inner Rust-space loops. Using the same test example as #10782, I had the timings go from 2.01(3)s on
main
to 1.88(2)s s with this PR (the numbers are larger because I've got webex open at the moment lol), and the improvements will stack almost perfectly with the improvements of #10782.This PR will conflict slightly with #10782, and I'll update whichever merges second.