Skip to content

performance(sierra-gas): Replaced maps enumerating all statements with Vecs.#9545

Merged
orizi merged 1 commit intomainfrom
orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs
Jan 27, 2026
Merged

performance(sierra-gas): Replaced maps enumerating all statements with Vecs.#9545
orizi merged 1 commit intomainfrom
orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 26, 2026

Summary

Optimized the excess cost computation in the Sierra gas analysis by replacing UnorderedHashMap and UnorderedHashSet with more efficient vector-based data structures. This change improves performance by using direct indexing instead of hash-based lookups when tracking statement costs.


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 uses hash-based data structures (UnorderedHashMap and UnorderedHashSet) for tracking excess costs and finalized statements during gas analysis. Since statements are already indexed sequentially, we can use more efficient vector-based structures with direct indexing, avoiding the overhead of hash computations and lookups.


What was the behavior or documentation before?

The code used UnorderedHashMap<StatementIdx, CostType> and UnorderedHashSet<StatementIdx> for tracking excess costs and finalized statements, requiring hash lookups for each access.


What is the behavior or documentation after?

The implementation now uses vec![None; self.program.statements.len()] and vec![false; self.program.statements.len()] with direct indexing, which provides faster access to the same data without changing the algorithm's behavior.


Additional context

This optimization is particularly beneficial for large programs with many statements, as it reduces the computational overhead during gas analysis without changing the functional behavior of the cost computation.

@reviewable-StarkWare
Copy link

This change is Reviewable

@orizi orizi marked this pull request as ready for review January 26, 2026 21:14
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).

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.

@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 force-pushed the orizi/01-26-performance_sierra-to-casm_reduced_many_of_the_returning_calls_to_gas_functions branch from 0119921 to 78aee97 Compare January 27, 2026 11:26
@orizi orizi force-pushed the orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs branch from 5364bc8 to 6201638 Compare January 27, 2026 11:26
@orizi orizi changed the base branch from orizi/01-26-performance_sierra-to-casm_reduced_many_of_the_returning_calls_to_gas_functions to graphite-base/9545 January 27, 2026 12:26
…h Vecs.

SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface change.
@orizi orizi force-pushed the graphite-base/9545 branch from 78aee97 to 5f1a0bd Compare January 27, 2026 12:43
@orizi orizi force-pushed the orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs branch from 6201638 to ebb429a Compare January 27, 2026 12:43
@orizi orizi changed the base branch from graphite-base/9545 to main January 27, 2026 12:43
@orizi orizi enabled auto-merge January 27, 2026 12:44
@orizi orizi added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit a12181a Jan 27, 2026
108 checks passed
@orizi orizi deleted the orizi/01-26-performance_sierra-gas_replaced_maps_enumerating_all_statements_with_vecs 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