-
Notifications
You must be signed in to change notification settings - Fork 12
View: Truncate instead of Copy #192
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
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, |
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:
|
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.
nice
Learnt something new here ! Thanks @wjmelements |
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