Skip to content

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 17, 2026

Summary

Optimized the take_args and put_results functions by requiring ExactSizeIterator instead of just Iterator, 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:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The current implementation of take_args and put_results functions doesn't pre-allocate memory for the collections they build, which can lead to multiple reallocations as elements are added. By requiring ExactSizeIterator, 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 Iterator and allocated collections with default capacity, causing potential reallocations as elements were added.


What is the behavior or documentation after?

Now the functions require ExactSizeIterator and 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.

@reviewable-StarkWare
Copy link

This change is Reviewable

@orizi orizi marked this pull request as ready for review January 17, 2026 08:13
@orizi orizi force-pushed the orizi/01-17-performance_orizi_made_allocations_for_state_edits_more_efficient branch from 561ab13 to ea40ca4 Compare January 20, 2026 10:19
@orizi orizi force-pushed the orizi/01-16-performance_sierra-to-casm_check_types_match_accepts_iterator_-_avoids_vec_allocation_and_concretetypeid_clones branch from 9e5638e to 468b295 Compare January 20, 2026 10:19
@orizi orizi changed the base branch from orizi/01-16-performance_sierra-to-casm_check_types_match_accepts_iterator_-_avoids_vec_allocation_and_concretetypeid_clones to graphite-base/9494 January 20, 2026 10:34
Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @eytan-starkware).

SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface changes.
@orizi orizi force-pushed the graphite-base/9494 branch from 468b295 to d52acf8 Compare January 20, 2026 10:50
@orizi orizi force-pushed the orizi/01-17-performance_orizi_made_allocations_for_state_edits_more_efficient branch from ea40ca4 to 020210a Compare January 20, 2026 10:50
@orizi orizi changed the base branch from graphite-base/9494 to main January 20, 2026 10:50
@orizi orizi enabled auto-merge January 20, 2026 10:51
@orizi orizi added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit df675fe Jan 20, 2026
55 checks passed
@orizi orizi deleted the orizi/01-17-performance_orizi_made_allocations_for_state_edits_more_efficient branch January 20, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants