Skip to content

performance(sierra-to-casm): Better top-stack-check data-structure.#9547

Merged
orizi merged 1 commit intomainfrom
orizi/01-27-performance_sierra-to-casm_better_top-stack-check_data-structure
Jan 27, 2026
Merged

performance(sierra-to-casm): Better top-stack-check data-structure.#9547
orizi merged 1 commit intomainfrom
orizi/01-27-performance_sierra-to-casm_better_top-stack-check_data-structure

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 27, 2026

Summary

Improved the validation of stack top variables in the Sierra to CASM compiler by replacing the UnorderedHashMap with a more efficient vector-based approach. Also replaced zip_eq with standard zip for better compatibility and added a new parameter to validate_stack_top to track stack top size more accurately.


Type of change

Please check one:

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

⚠️ Note:
To keep maintainer workload sustainable, we generally do not accept PRs that
are only minor wording, grammar, formatting, or style changes.
Such PRs may be closed without detailed review.


Why is this change needed?

The current implementation uses an UnorderedHashMap to track stack top variables, which is less efficient than a direct vector-based approach. This change optimizes the validation process by using a vector with direct indexing instead of hash map lookups, improving performance in the Sierra to CASM compilation process.


What was the behavior or documentation before?

Previously, the code used an UnorderedHashMap to track stack top variables and relied on zip_eq for strict iteration, which could be unnecessarily restrictive in some cases.


What is the behavior or documentation after?

Now the code uses a more efficient vector-based approach to track stack top variables, with direct indexing instead of hash map lookups. It also uses standard zip instead of zip_eq for better compatibility, and tracks stack top size more accurately with an explicit parameter.


Additional context

This change is part of ongoing efforts to optimize the Sierra to CASM compilation process, which is a critical part of the Cairo compiler pipeline.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

@orizi orizi changed the base branch from orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs to graphite-base/9547 January 27, 2026 12:43
Since the size of the stack increase is known, using a vec is easy.

SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface change.
@orizi orizi force-pushed the orizi/01-27-performance_sierra-to-casm_better_top-stack-check_data-structure branch from 8f204b9 to 9ad4ccf Compare January 27, 2026 13:00
@orizi orizi force-pushed the graphite-base/9547 branch from 6201638 to a12181a Compare January 27, 2026 13:00
@orizi orizi changed the base branch from graphite-base/9547 to main January 27, 2026 13:00
@orizi orizi enabled auto-merge January 27, 2026 13:00
@orizi orizi added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 7ddbf0e Jan 27, 2026
108 checks passed
@orizi orizi deleted the orizi/01-27-performance_sierra-to-casm_better_top-stack-check_data-structure branch January 27, 2026 14:37
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.

3 participants