latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
758 stars 189 forks source link

gas-report vs optimizer #1267

Open dk1a opened 1 year ago

dk1a commented 1 year ago

The optimizer can put some things outside of the startGasReport/endGasReport frame (using gasReport modifier doesn't change this). Usually it's unimportant, especially for costly functions, but it would be useful to have a way for gas-report command to optionally include the cost of a whole test function (like what forge test --gas-report --mt testName returns), ideally only the contents, without the function's overhead

(on 2nd thought, although I mention the optimizer it could be the compiler. I didn't delve into the specifics of everything that's going on here)

alvrs commented 1 year ago

is it possible to disable the optimizer via an env variable that we can set while generating the gas report, similar to here: https://github.com/latticexyz/mud/blob/main/packages/gas-report/ts/index.ts#L105 ?

dk1a commented 1 year ago

is it possible to disable the optimizer via an env variable that we can set while generating the gas report, similar to here: https://github.com/latticexyz/mud/blob/main/packages/gas-report/ts/index.ts#L105 ?

That env var isn't a foundry thing, it's just used for conditional things within solidity. Optimizer is a compiler flag so I don't think you can disable it for specific lines/tests/files. You could run a second set of tests without an optimizer, though that's a hassle. Anyways it wouldn't be very useful imo, unoptimized code costs more gas and isn't representative of the real gas usage