20,000 USDC
View results
Submission Details
Severity: gas
Valid

Multiple accesses of a mapping/array should use a local variable cache

Summary Caching multiple accesses of a mapping or array in a local variable can potentially save gas in certain scenarios. Let's explore how and when this gas optimization can be beneficial.

When you access elements of a mapping or array multiple times within a single function, it involves multiple reads from storage or memory. Each access incurs gas costs due to the need to load data from storage or memory.
By caching the mapping or array elements in a local variable, you can avoid redundant reads and reduce gas consumption.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.