Does anyone know if solidity does any caching when checking the bounding condition of a for loop, or if I'm checking against a storage variable is it better to create a copy of that variable on the stack to compare against, from a gas utilisation perspective?

Jan 23, 2022, 10:20 PM
i.e does:
for (uint i; i < myStorageVariable; i++) {...
use more gas than
uint myLocalVariable = myStorageVariable;
for (uint i; i < myLocalVariable; i++) {...
Jan 23, 2022, 10:21 PM
It is better to always generate a copy to do this task.
the second way is the correct way (for gas)
Jan 23, 2022, 10:28 PM

© 2024 Draquery.com All rights reserved.