Skip to content

performance(sierra-to-casm): Reduced many of the returning calls to gas functions.#9541

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

performance(sierra-to-casm): Reduced many of the returning calls to gas functions.#9541
orizi merged 1 commit intomainfrom
orizi/01-26-performance_sierra-to-casm_reduced_many_of_the_returning_calls_to_gas_functions

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 26, 2026

Summary

Refactored the gas cost calculation in Sierra by adding methods to the BranchCost enum that encapsulate the logic for calculating pre-cost and post-cost. This change simplifies the core_libfunc_cost function in core_libfunc_cost.rs by leveraging these new methods instead of using the previous approach with zip_eq.


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 previous implementation used separate functions for pre-cost and post-cost calculations, which required zipping the results together. This approach was less maintainable and less efficient. By moving the cost calculation logic into methods on the BranchCost enum, we make the code more modular and easier to understand.


What was the behavior or documentation before?

Previously, the code used separate core_libfunc_precost and core_libfunc_postcost functions, and then zipped their results together in the core_libfunc_cost function. This approach was more complex and less direct.


What is the behavior or documentation after?

Now, the BranchCost enum has precost and postcost methods that encapsulate the cost calculation logic. The core_libfunc_cost function in core_libfunc_cost.rs directly uses these methods, making the code more straightforward and maintainable.


Additional context

This refactoring maintains backward compatibility by keeping the original core_libfunc_precost and core_libfunc_postcost functions, but they now delegate to the new methods. This allows for a gradual transition to the new approach.

@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 2 files and all commit messages, and made 2 comments.
Reviewable status: all 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):

/// Returns a precost value for a libfunc - the cost of non-step tokens.
/// This is a helper function to implement costing both for creating
/// gas equations and getting actual gas cost after having a solution.

Should also be removed with postcost

@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 changed the base branch from orizi/01-26-performance_sierra-gas_reduced_many_map_actions_by_refacoring_costops to graphite-base/9541 January 27, 2026 11:46
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 reviewed 1 file and all commit messages, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware and @TomerStarkware).

…gas` functions.

SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface change.
@orizi orizi force-pushed the graphite-base/9541 branch from 719e5a8 to 67c062a Compare January 27, 2026 12:27
@orizi orizi force-pushed the orizi/01-26-performance_sierra-to-casm_reduced_many_of_the_returning_calls_to_gas_functions branch from 78aee97 to d734bfa Compare January 27, 2026 12:27
@orizi orizi changed the base branch from graphite-base/9541 to main January 27, 2026 12:27
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 reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware and @TomerStarkware).

@orizi orizi enabled auto-merge January 27, 2026 12:32
@orizi orizi added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 5f1a0bd Jan 27, 2026
108 checks passed
@orizi orizi deleted the orizi/01-26-performance_sierra-to-casm_reduced_many_of_the_returning_calls_to_gas_functions 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