performance(orizi): Made allocations for state edits more efficient. #9494
+5
−4
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
Optimized the
take_argsandput_resultsfunctions by requiringExactSizeIteratorinstead of justIterator, allowing for pre-allocation of vectors and reserving capacity in hash maps. This change improves performance by reducing memory reallocations during Sierra to CASM compilation.Type of change
Please check one:
Why is this change needed?
The current implementation of
take_argsandput_resultsfunctions doesn't pre-allocate memory for the collections they build, which can lead to multiple reallocations as elements are added. By requiringExactSizeIterator, we can know the size upfront and allocate the right amount of memory once, improving performance.What was the behavior or documentation before?
Previously, the functions accepted any
Iteratorand allocated collections with default capacity, causing potential reallocations as elements were added.What is the behavior or documentation after?
Now the functions require
ExactSizeIteratorand use the iterator's length to pre-allocate collections with the exact required capacity, avoiding reallocations.Additional context
This change is particularly beneficial for the Sierra to CASM compilation process, which involves many operations on collections of variable references. The performance improvement will be more noticeable for larger programs with many variables.