Skip to content

performance(sierra-gas): Reduced many map actions by refacoring CostOps.#9536

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

performance(sierra-gas): Reduced many map actions by refacoring CostOps.#9536
orizi merged 1 commit intomainfrom
orizi/01-26-performance_sierra-gas_reduced_many_map_actions_by_refacoring_costops

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 26, 2026

Summary

Refactored the cost operations in the Sierra gas module to simplify the code and improve performance.


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?

A lot of useless map iterations and operations were reduced.


Additional context

The changes to the cost operations simplify the code by:

  1. Using a more specific CostValueType instead of the generic CostType
  2. Leveraging standard operators (+, -, etc.) instead of custom add/sub methods
  3. Making token cost operations return Option values for better error handling
  4. Simplifying collection operations with more direct implementations

@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.

@eytan-starkware reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: 3 of 4 files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware, @orizi, and @TomerStarkware).


crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs line 816 at r1 (raw file):

fn statement_vars_cost<'a, Ops: CostOperations, TokenTypes: Iterator<Item = &'a CostTokenType>>(
    ops: &Ops,
    token_types: TokenTypes,

Move precost iter inside this function

SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface changes.
@orizi orizi force-pushed the orizi/01-26-performance_sierra-gas_reduced_many_map_actions_by_refacoring_costops branch from 719e5a8 to 4355234 Compare January 27, 2026 11:46
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, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @ilyalesokhin-starkware and @TomerStarkware).

Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi made 1 comment.
Reviewable status: 3 of 4 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware, @ilyalesokhin-starkware, and @TomerStarkware).


crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs line 816 at r1 (raw file):

Previously, eytan-starkware wrote…

Move precost iter inside this function

Done.

@orizi orizi enabled auto-merge January 27, 2026 11:47
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 all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware and @TomerStarkware).

@orizi orizi added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 67c062a Jan 27, 2026
55 checks passed
@orizi orizi deleted the orizi/01-26-performance_sierra-gas_reduced_many_map_actions_by_refacoring_costops 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