View: Truncate instead of Copy#192
Merged
wjmelements merged 4 commits intoFilOzone:mainfrom Jul 29, 2025
Merged
Conversation
Collaborator
Author
|
This change's diff to the It's a small improvement for small arrays but it would be larger for large arrays. There is a also a small reduction in codesize. While these view methods are unlikely to be used during execution, if their gas usage is too large, |
Collaborator
Author
I'm not sure that this is the case for Filecoin but I still think this is a good change. For Ethereum, here is the gas savings by number of results:
|
Contributor
|
Learnt something new here ! Thanks @wjmelements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reviewer @aarshkshah1992
Solidity memory arrays cannot increase in size once allocated, but it safe to truncate them.
Because memory gas is quadratic, the cost of this copy grows quickly with the size of the array.
By truncating the array we can avoid the copy step.
Changes
Test plan