-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Description
Description
Certain evm.*.* output is generated in memory even when not requested through outputSelection. This wastes resources on computing values that are discarded immediately after.
In Foundry, we updated the outputSelection to only include specific fields of evm.bytecode.* as we don't make use of all of them, which was a substantial win in compilation times: foundry-rs/compilers#231. The biggest contributor to this was excluding generatedSources from the JSON, as these can become very large.
The default output selection is now:
["abi","evm.bytecode.object","evm.bytecode.sourceMap","evm.bytecode.linkReferences","evm.deployedBytecode.object","evm.deployedBytecode.sourceMap","evm.deployedBytecode.linkReferences","evm.deployedBytecode.immutableReferences","evm.methodIdentifiers","metadata"]However, I profiled the compiler and noticed that it was still calling generatedSources.
Here's a profile generated from forge build --use <solc 0.8.29-develop.2024.10.22+commit.9c4995a9.mod.Linux.g++> on superform-xyz/superform-core @ 7b69077 (this is an older build of solc but it should still apply): https://share.firefox.dev/3BaYnLD, using samply
You can see that there is a 4% frame of CompilerStack::generatedSources.
I believe this happens in StandardCompiler. It is generated and passed eagerly to collectEVMObject when any evm.bytecode* output is requested https://github.com/ethereum/solidity/blob/8da621c41d67d8ee5a74157f28efa670a7370746/libsolidity/interface/StandardCompiler.cpp#L1509-L1522
but then discarded if the individual evm.bytecode.generatedSources is not requested https://github.com/ethereum/solidity/blob/8da621c41d67d8ee5a74157f28efa670a7370746/libsolidity/interface/StandardCompiler.cpp#L399-L400
The same applies to other fields, like sourceMap.
Environment
- Compiler version: 0.8.28, main
- Target EVM version (as per compiler settings): Paris
- Framework/IDE (e.g. Truffle or Remix): Foundry
- EVM execution environment / backend / blockchain client: Foundry
- Operating system: Linux
Steps to Reproduce
Compile anything with evm.bytecode.object output selection, see above.