PaulRBerg / prb-proxy

Proxy contract to compose Ethereum transactions
https://prbproxy.com
MIT License
273 stars 47 forks source link

Declare "method" outside of the loop in "uninstallPlugin" #154

Closed PaulRBerg closed 1 year ago

PaulRBerg commented 1 year ago

This is @IaroslavMazur's suggestion:

it should be more efficient to declare method outside the for loop. Possibly, even with --via-ir.

The reference is for the method variable declaration here:

https://github.com/PaulRBerg/prb-proxy/blob/27594d50f049330c5acfa6cf45448152a2932ecf/src/PRBProxyRegistry.sol#L264

PaulRBerg commented 1 year ago

I made a gas comparison now. What I did:

Breakdown:

Tx Gas Cost
Inside the Loop 122,310
Outside the Loop 122,358

Thus, contrary to our expectations, declaring method outside the loop increases the cost. And the reason for this is via IR - speaking of which, I've tweeted about how surprising via IR can be here.

IaroslavMazur commented 1 year ago

Thus, contrary to our expectations, declaring method outside the loop increases the cost. And the reason for this is via IRhere.

How very weird, indeed! 🤔

Thank you for diving into this!