Skip to content

performance(sierra-to-casm): Made ApplyApChange inplace.#9448

Merged
orizi merged 1 commit intomainfrom
orizi/01-11-performance_sierra-to-casm_made_referenceexpression_applyapchange_more_inplace
Jan 13, 2026
Merged

performance(sierra-to-casm): Made ApplyApChange inplace.#9448
orizi merged 1 commit intomainfrom
orizi/01-11-performance_sierra-to-casm_made_referenceexpression_applyapchange_more_inplace

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 11, 2026

Summary

Refactored the ApplyApChange trait to modify values in-place rather than returning new values. This changes the signature from fn apply_known_ap_change(self, ap_change: usize) -> Option<Self> to fn apply_known_ap_change(&mut self, ap_change: usize) -> bool, which simplifies error handling and avoids unnecessary cloning. The implementation also improves the handling of AP change overflow by using num_traits::ToPrimitive for safer conversions.


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 of ApplyApChange required cloning and recreating objects when applying AP changes. By modifying values in-place, we can avoid unnecessary allocations and improve performance, especially in code paths that apply AP changes frequently.


What was the behavior or documentation before?

Previously, apply_known_ap_change consumed self and returned a new instance wrapped in an Option, requiring callers to handle the None case separately and often leading to unnecessary cloning of data structures.


What is the behavior or documentation after?

Now apply_known_ap_change takes &mut self and returns a boolean indicating success, which is more efficient and follows a more conventional error-handling pattern. The implementation also uses num_traits::ToPrimitive for safer numeric conversions.


Additional context

This change affects multiple implementations of the ApplyApChange trait across the codebase, including ResOperand, CellRef, DerefOrImmediate, BinOpOperand, CellExpression, and ReferenceExpression. Tests have been updated to use a helper function that maintains the previous API for testing purposes.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator Author

orizi commented Jan 11, 2026

@orizi orizi marked this pull request as ready for review January 11, 2026 14:26
Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

@orizi orizi force-pushed the orizi/01-11-performance_sierra-to-casm_made_referenceexpression_applyapchange_more_inplace branch from 51f6ea1 to e397122 Compare January 13, 2026 13:52
@orizi orizi force-pushed the orizi/01-11-performance_sierra-to-casm_better_moving_of_annotations branch from 5ee68e9 to 0277b49 Compare January 13, 2026 13:52
@orizi orizi changed the base branch from orizi/01-11-performance_sierra-to-casm_better_moving_of_annotations to graphite-base/9448 January 13, 2026 15:47
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).

Minor performance gain.
Prevents recursive reconstruction.

SIERRA_UPDATE_MINOR_CHANGE_TAG=No interface change.
@orizi orizi changed the base branch from graphite-base/9448 to main January 13, 2026 17:10
@orizi orizi force-pushed the orizi/01-11-performance_sierra-to-casm_made_referenceexpression_applyapchange_more_inplace branch from e397122 to 86e315e Compare January 13, 2026 17:10
@orizi orizi enabled auto-merge January 13, 2026 17:15
@orizi orizi added this pull request to the merge queue Jan 13, 2026
Merged via the queue into main with commit 911ef92 Jan 13, 2026
55 checks passed
@orizi orizi deleted the orizi/01-11-performance_sierra-to-casm_made_referenceexpression_applyapchange_more_inplace branch January 13, 2026 17:34
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