-
Notifications
You must be signed in to change notification settings - Fork 137
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
calldataViewFunctions
may encourage gas inefficiency
#14
Comments
the issue referenced mentions that memory is cheaper if you access more than once, but if you're accessing more than once, you should be using a stack variable anyway. I'll try to come up with some test cases to tease out when it make sense to use one vs the other |
@IllIllI000 I am definitely interested in such test cases |
please remind me after March 25th (GMX contest end) |
⏰ it's after March 25th (sorry was reading the issues and maybe you still want to be reminded lol) |
Ah, thanks I did indeed forget. Still busy with other work, but won't submit this finding again until I have it worked out |
@CodeSandwich do you have an example where |
@IllIllI000 I think that your results are spot on, I've tried doing some benchmarks myself and for arrays of uint256 calldata was always cheaper no matter how many times the array was accessed, and for uint248 or smaller memory was always cheaper. It's also true for |
The
calldataViewFunctions
flags allmemory
parameters as gas inefficient if they aren't modified. This isn't always the case,memory
arguments are often cheaper thancalldata
. This is becausecalldata
is not trusted by Solidity and each access does many sanity checks whilememory
arguments are sanity checked only once, when loading. I've seen a gas usage drop after switching fromcalldata
tomemory
in the contracts I've been working on and it even has an issue in Solidity repo, which doesn't seem to be ever solved due tocalldata
arguments needing the sanity checks: ethereum/solidity#12103.The text was updated successfully, but these errors were encountered: