How much accessing msg.sender costs? Is it useful to store it in a variable and then use it instead of accessing msg.sender multiple times? I have to access current user variable multiple times in a function.
How much accessing msg.sender costs? Is it useful to store it in a variable and then use it instead of accessing msg.sender multiple times? I have to access current user variable multiple times in a function.
Using msg.sender will always be cheaper than using a local variable.
The reason is the following:
The CALLER operation which is reading the msg.sender global variable costs 2.
While MLOAD/MSTORE operations which are memory operations (storage where local variables are stored) costs 3.
You can check gas costs for each operation here.