If you hit a stack limit then a trick I use is to create a local array with constant offsets to the variable you need. That way the compiler only sees 1 variable (the array) and the constants rather than the n variables in the array. Constants make the code a bit more readable than literal numbers.
Not sure what the gas cost is of an array lookup which is bound to be higher than just a variable, but if it means that the function can compile its the cost of doing it.
Basics of Smart Contract Gas Optimization with Solidity
If you hit a stack limit then a trick I use is to create a local array with constant offsets to the variable you need. That way the compiler only sees 1 variable (the array) and the constants rather than the n variables in the array. Constants make the code a bit more readable than literal numbers.
Not sure what the gas cost is of an array lookup which is bound to be higher than just a variable, but if it means that the function can compile its the cost of doing it.
Thank you!