-
Notifications
You must be signed in to change notification settings - Fork 738
performance(sierra-gas): Smaller equivalent costs map. #9535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
eytan-starkware
left a comment
There was a problem hiding this 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: all files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware).
crates/cairo-lang-sierra-gas/src/compute_costs.rs line 110 at r1 (raw file):
// Keys are unique since we're iterating over value's keys. PreCost(CostTokenMap::unchecked_from_iter( value.0.iter().filter_map(|(k, v)| (*v >= 0).then_some((*k, *v))),
Why is it ok to have a non-full map here? Shouldn't rectify have a zero default for anything negative?
e6b5dfc to
e612c14
Compare
7cc82db to
d56b482
Compare
SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface change.
e612c14 to
d0f1a87
Compare
d56b482 to
b7b22af
Compare
orizi
left a comment
There was a problem hiding this 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @TomerStarkware).
crates/cairo-lang-sierra-gas/src/compute_costs.rs line 110 at r1 (raw file):
Previously, eytan-starkware wrote…
Why is it ok to have a non-full map here? Shouldn't rectify have a zero default for anything negative?
the map already is a result of a sub operation - 0 values have been removed. no reason to keep values as 0.
eytan-starkware
left a comment
There was a problem hiding this 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, made 1 comment, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware).

Summary
Optimized the
rectifymethod inPreCostimplementation by replacing a map-and-max operation with a filter-map approach. Instead of iterating through all values and replacing negative values with zero, the new implementation simply filters out negative values entirely, keeping only non-negative entries in the resulting cost map.Type of change
Please check one:
Why is this change needed?
The current implementation of
rectifyinPreCostiterates through all values and replaces negative values with zero. This is inefficient since we're keeping entries with zero values in the map. The new implementation filters out negative values entirely, which reduces the size of the resulting map and improves performance.What was the behavior or documentation before?
Previously, the
rectifymethod would iterate through all entries in the cost map and replace any negative values with zero, keeping all entries in the map.What is the behavior or documentation after?
Now, the
rectifymethod filters out any entries with negative values, keeping only entries with non-negative values in the resulting map. This reduces the map size and improves performance.Additional context
This change maintains the same functional behavior while making the code more efficient. The Sierra gas computation will produce the same results, but with potentially fewer entries in the cost maps.