optimism
optimism copied to clipboard
massive increase in bundle size between `@eth-optimism/contracts` versions `0.5.29` --> `0.5.33`
Describe the bug
Somewhere strictly after the release 0.5.29 and on-or-before the release 0.5.33, the bundle size of @eth-optimism/contracts increased enormously, from over 2MB to over 4.4MB.
As of now, @eth-optimism is essentially an order of magnitude larger than anything else in my project, which is crazy! it was already bizarrely large before this, but this is essentially not tolerable. Please look into this and address this, or I may have to downgrade. many thanks in advance.
To Reproduce add
"dependencies": {
...
"@eth-optimism/sdk": "^1.2.0",
...
}
to package.json of any project; then run the project through Webpack Bundle Analyzer.
Expected behavior The bundle size should be < 1MB.
Screenshots
this is a screenshot of the relevant portion of Webpack Bundle Analyzer.

System Specs:
- OS: Mac OS 12.5.1
- Package Version (or commit hash): relevant section of current
yarn.lockfile is below
"@eth-optimism/[email protected]":
version "0.5.4"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts-bedrock/-/contracts-bedrock-0.5.4.tgz#d2dbdc7fcb7ef729d2682b898d742fd2f1482bb8"
integrity sha512-+1dnI17DF+p3Q80qNhvfmMF0/HIb7PhAw4eJLjBWUbyGVVmUffZC4XiVYt5Rx3kFGUc50gDzPo30rUtdj4zE5w==
dependencies:
"@eth-optimism/core-utils" "^0.9.3"
"@openzeppelin/contracts" "4.7.3"
"@openzeppelin/contracts-upgradeable" "4.7.3"
ethers "^5.6.8"
hardhat "^2.9.6"
"@eth-optimism/[email protected]":
version "0.5.33"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts/-/contracts-0.5.33.tgz#1adeb902ff849152ecdb8639af5ba76dfc27c213"
integrity sha512-lOj0psjl/7oydUXuSXhZ3P55zAXBNSgK6OzZeCW6JQ+drN+1OEdyp/MYKrSh8Cw8fW2k9MMdWbOuTa7/Blb0hA==
dependencies:
"@eth-optimism/core-utils" "0.9.3"
"@ethersproject/abstract-provider" "^5.6.1"
"@ethersproject/abstract-signer" "^5.6.2"
"@eth-optimism/[email protected]", "@eth-optimism/core-utils@^0.9.3":
version "0.9.3"
resolved "https://registry.yarnpkg.com/@eth-optimism/core-utils/-/core-utils-0.9.3.tgz#40c0271f815af68e0a4715e97a045a96462df7b6"
integrity sha512-b3V8qBgM0e85wdp3CNdJ6iSUvjT2k86F9oCAYeCIXQcQ6+EPaetjxP0T6ct6jLVepnJjoPRlW/lvWslKk1UBGg==
dependencies:
"@ethersproject/abstract-provider" "^5.6.1"
"@ethersproject/properties" "^5.6.0"
"@ethersproject/providers" "^5.6.8"
"@ethersproject/transactions" "^5.6.2"
"@ethersproject/web" "^5.6.1"
bufio "^1.0.7"
chai "^4.3.4"
ethers "^5.6.8"
"@eth-optimism/sdk@^1.2.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@eth-optimism/sdk/-/sdk-1.6.0.tgz#18acaf2e9ccf0dff90e5629e8b1cd191b53e6629"
integrity sha512-Z/NnZskaqeSHr6iQEcdOgmC4QoEGFqglkMmk0cwgN9TGbSd+gz65U6gQRh/MaX4r4ZV6uQEkOCmdHeXWfhlj+Q==
dependencies:
"@eth-optimism/contracts" "0.5.33"
"@eth-optimism/contracts-bedrock" "0.5.4"
"@eth-optimism/core-utils" "0.9.3"
lodash "^4.17.21"
merkletreejs "^0.2.27"
rlp "^2.2.7"
Additional context let me know if i can provide any further diagnostic information. many thanks in advance.
OP Labs is running a mandatory week off this week for some R&R before Bedrock, so apologies for the inevitably slow response here until next week. Agree this is an issue and should be very easily resolvable by cutting out a majority of the deployment files. Thanks for bringing this up, I'll make sure this is fixed as soon as we get back.
ok, thanks for the response. you'll be back this coming Monday, or not till the week after? please keep me posted; thanks.
People will be back on Sept 5th. I'll make sure to ping you here as soon as a fix is released. Thanks again for reporting this!
Alright I was able to significantly reduce the bundle size by not exporting data that seemed relatively unnecessary.
Original bundle size:
npm notice === Tarball Details ===
npm notice name: @eth-optimism/contracts
npm notice version: 0.5.34
npm notice package size: 3.0 MB
npm notice unpacked size: 15.3 MB
npm notice shasum: d704ca30cfae3eeb468b6b8ae3dad3c46f283f4b
npm notice integrity: sha512-8VPNS0yGA6SrY[...]j3ySbTJluxnew==
npm notice total files: 503
npm notice
Fixed bundle size:
npm notice === Tarball Details ===
npm notice name: @eth-optimism/contracts
npm notice version: 0.5.34
npm notice package size: 269.7 kB
npm notice unpacked size: 2.0 MB
npm notice shasum: c1e5fedb812b09c4e4ffc7760002be5b9619bd9f
npm notice integrity: sha512-EX4zJaKEQtwo9[...]3WADWMpZGVb5A==
npm notice total files: 366
npm notice
I will make a PR when people get back and are able to review.
I was trying to cut things down even more but about half of the bundle is just typechain, which is unfortunate.
i see, gotcha. cool! this should be plenty. follow up here as soon as the PR is ready and/or published and released on npm, if you don't mind. thanks again!
0.5.34 should resolve the issue once released. We will probably do a release today or tomorrow.
do you mind alerting here once this actually goes live on npm? thanks. edit just saw the above, nice—would be helpful if you could post here when that's done.
Will do.
@firnprotocol sorry for the delay here. 0.5.34 has been published: https://www.npmjs.com/package/@eth-optimism/contracts
note that i am now receiving warnings during webpack compilation:
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 266:22-109
Module not found: Error: Can't resolve '../artifacts/contracts/test-helpers/FailingReceiver.sol/FailingReceiver.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 271:16-91
Module not found: Error: Can't resolve '../artifacts/contracts/test-helpers/TestERC20.sol/TestERC20.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 276:31-145
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/bridge/TestLib_CrossDomainUtils.sol/TestLib_CrossDomainUtils.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 281:23-120
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/codec/TestLib_OVMCodec.sol/TestLib_OVMCodec.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 286:24-121
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/rlp/TestLib_RLPReader.sol/TestLib_RLPReader.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 291:24-121
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/rlp/TestLib_RLPWriter.sol/TestLib_RLPWriter.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 296:33-154
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/standards/TestLib_AddressAliasHelper.sol/TestLib_AddressAliasHelper.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 301:25-125
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/trie/TestLib_MerkleTrie.sol/TestLib_MerkleTrie.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 306:31-143
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/trie/TestLib_SecureMerkleTrie.sol/TestLib_SecureMerkleTrie.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 311:21-114
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/utils/TestLib_Buffer.sol/TestLib_Buffer.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 316:27-132
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/utils/TestLib_Bytes32Utils.sol/TestLib_Bytes32Utils.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 321:25-126
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/utils/TestLib_BytesUtils.sol/TestLib_BytesUtils.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
WARNING in ./node_modules/@eth-optimism/contracts/dist/contract-artifacts.js 326:25-126
Module not found: Error: Can't resolve '../artifacts/contracts/test-libraries/utils/TestLib_MerkleTree.sol/TestLib_MerkleTree.json' in '/Users/benediamond/firn/node_modules/@eth-optimism/contracts/dist'
@ ./node_modules/@eth-optimism/contracts/dist/contract-defs.js 6:36-67
@ ./node_modules/@eth-optimism/contracts/dist/index.js 17:13-39
@ ./node_modules/@eth-optimism/sdk/dist/cross-chain-messenger.js 30:20-54
@ ./node_modules/@eth-optimism/sdk/dist/index.js 19:13-47
@ ./src/ui/MainPanel/index.js 19:0-64 32:19-31 157:34-47
@ ./src/App.js 10:0-41 51:51-60
@ ./src/index.js 6:0-28 14:38-41
appears to work though, despite the warnings...
let me know if you're able to reproduce?
btw, even after this upgrade, optimism is still quite large (~1.3 MB). for perspective, it is over twice as large as ethers.js (?!), and over twice as large as the next-largest package. i really don't see why this should be. moreover, it is still larger than it was in version 0.5.29. one way this can happen is if you git track "detailed" compiler output (including abstract syntax tree). i wonder if you all are doing this?
here is my entire node_modules folder, in the bundle analyzer:
note ethers in the bottom middle.
and the relevant portion of yarn.lock:
"@eth-optimism/[email protected]":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts-bedrock/-/contracts-bedrock-0.6.0.tgz#037becf54be35ed65f17ebdabac0b8c7472dae59"
integrity sha512-I9uaq77NeQX0e/lVe9s+4N3vUQXLGNmfmBdstAh1I24Q0n9nMC+L0c5TOO/rpG/Tqog9XmBn7tghqw/ussLGhQ==
dependencies:
"@eth-optimism/core-utils" "^0.10.0"
"@openzeppelin/contracts" "4.7.3"
"@openzeppelin/contracts-upgradeable" "4.7.3"
ethers "^5.6.8"
hardhat "^2.9.6"
"@eth-optimism/[email protected]":
version "0.5.34"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts/-/contracts-0.5.34.tgz#36d904a2c6809cbd49309534936d714506edd55a"
integrity sha512-TgMvzevw14bkPbrVp3XqSrEI0SEyyzs69rQiurHpeY72tmN+8XBcTOF00tnfjqQA6MVPQvoQf1hQLnEPzmRpdQ==
dependencies:
"@eth-optimism/core-utils" "0.10.0"
"@ethersproject/abstract-provider" "^5.6.1"
"@ethersproject/abstract-signer" "^5.6.2"
"@eth-optimism/[email protected]", "@eth-optimism/core-utils@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@eth-optimism/core-utils/-/core-utils-0.10.0.tgz#512872fedd4fc3b0f244bd45a73a92eed7c08aa2"
integrity sha512-2npqQcmqWI1QqdK5jvsgplZ2bv2yrySUgDCIT8lSyiowhsadTN2oaXa0Ja4jPsn6XN9Mv87WMGz3RwwwEDZu0w==
dependencies:
"@ethersproject/abi" "^5.6.3"
"@ethersproject/abstract-provider" "^5.6.1"
"@ethersproject/address" "^5.6.1"
"@ethersproject/bignumber" "^5.6.1"
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/constants" "^5.6.1"
"@ethersproject/contracts" "^5.6.2"
"@ethersproject/hash" "^5.6.1"
"@ethersproject/keccak256" "^5.6.1"
"@ethersproject/properties" "^5.6.0"
"@ethersproject/providers" "^5.6.8"
"@ethersproject/rlp" "^5.6.1"
"@ethersproject/transactions" "^5.6.2"
"@ethersproject/web" "^5.6.1"
bufio "^1.0.7"
chai "^4.3.4"
"@eth-optimism/sdk@^1.2.0":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@eth-optimism/sdk/-/sdk-1.6.1.tgz#cef7b2cc12c0ebaa99ab9520b93981ebd5551070"
integrity sha512-+VyFeFIamg1LQ9rPMRS3oDmnh0H8p3NAWoYjk8dnlxLrT2MvCjwxiUhe8cX7TuesLt8lREIWm3nGFQ3ijuRDfA==
dependencies:
"@eth-optimism/contracts" "0.5.34"
"@eth-optimism/contracts-bedrock" "0.6.0"
"@eth-optimism/core-utils" "0.10.0"
lodash "^4.17.21"
merkletreejs "^0.2.27"
rlp "^2.2.7"
upon investigating this a bit, it looks like you are storing/tracking both bytecode and deployedBytecode for all contracts (see e.g. the file @eth-optimism/contracts-bedrock/artifacts/contracts/L1/L1StandardBridge.sol/L1StandardBridge.json, which alone is ~57 KB). my guess is that you don't need these, and that if you removed these properties, the size would come down significantly. i.e., the client may need to know the ABI of these contracts, but it almost definitely doesn't need to know their bytecode, since it's not going to be deploying them. so my suggestion would be to revert the repo to how it was (to get rid of the warnings), but then remove the bytecode and deployedBytecode properties from all tracked contract JSON artifacts. thoughts...?
hi all, i hate to nag, but I don't see this issue as being fully resolved. can we revisit / reopen?
Reopening. 0.5.35 fixes the broken NPM package. Going to see about removing the bytecode.
@firnprotocol we're investigating this further. We have some ideas but they will likely require some small API changes.
any progress here? friendly bump.
any progress here? friendly bump.
Hey sorry, got swamped with some important Bedrock work. I should probably have some time over the weekend to take another stab at this.
Just a status update here, devcon is this week and I likely will not be able to work on this until after I'm back. Need to work on lots of slides and some Bedrock migration stuff.
Is this still an issue?
i stopped using optimism-sdk a while ago, since i was only using it for getL1GasPrice, and i realized that i can just query the on-chain oracle instead.
but as far as i can remember, it got slightly better, but was still quite bad.
Thank you for the update @firnprotocol
Optimism sdk bundle size is quite large and we have plans to offer alternatives that have smaller bundle sizes. Stay tuned
Closing this issue, it seems stale. Please re-open if any issues persist. Also note that TS things are being moved to https://github.com/ethereum-optimism/ecosystem