performance(sierra-to-casm): Avoid intermediate allocation in gas wallet update. #9492
+20
−27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Summary
Refactored the gas wallet mechanism in the Sierra-to-CASM compiler to improve error handling and clarify gas cost semantics. The changes include:
GasWalletErrorto reduce memory usagegas_changetogas_costto better reflect its purposesub_collectioninstead ofadd_collectionType of change
Please check one:
Why is this change needed?
The previous implementation had inconsistent semantics around gas costs, where negative values were used for costs and positive values for acquisitions. This made the code harder to understand and maintain. Additionally, the error handling for out-of-gas conditions was verbose and could be improved.
What was the behavior or documentation before?
Before, the gas wallet used
add_collectionwith sign-flipped values, and error messages were less clear about the exact state that caused the out-of-gas condition.What is the behavior or documentation after?
Now, the gas wallet directly uses
sub_collectionwith costs represented as positive values, making the code more intuitive. Error messages are more precise about what caused the out-of-gas condition, and memory usage is reduced by boxing the error type.