Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Review and optimize bundle dependencies #269

Open
acuarica opened this issue Nov 29, 2022 · 0 comments
Open

Review and optimize bundle dependencies #269

acuarica opened this issue Nov 29, 2022 · 0 comments
Labels
Epic needs investigated refactor Improve code or project quality

Comments

@acuarica
Copy link
Contributor

acuarica commented Nov 29, 2022

As a follow up of #263 and #245 (comment), we noticed that the main extension bundle is quite large. We need to review bundled dependencies and options, and remove or optimize any of these that are unused by the extension.

To analyze bundle dependencies, we use webpack-bundle-analyzer. You can get the analysis with

$ node node_modules/.bin/webpack --config webpack.prod.js --json > stats.json
$ npx webpack-bundle-analyzer stats.json out/src
Webpack Bundle Analyzer is started at http://127.0.0.1:8888
Use Ctrl+C to close it

The output is

image

Reducing bundle size by removing unnecessary large packages

Notice how the bundle has large dependencies that are apparently unused. For instance, let's see its larger dependencies

  • prettier. It was removed in Remove prettier from bundle #270. It's included because there is transitive dependency through @truffle#resolver#abi-to-sol#prettier, here

https://github.com/gnidan/abi-to-sol/blob/e19eba4c35ec1df075fc2d3d44067a01057f9f12/packages/abi-to-sol/src/solidity.ts#L18-L23

Even if it's being required dynamically, webpack is still including it in the final bundle.

Reducing bundle size by deduping Truffle packages

Another issue might arise from including the same package multiple times within Truffle. If we zoom in into Truffle,

image

we can see for instance that the package @truffle/codec is being included multiple times. We need to investigate is that is actually the case, and is so, include it just once.

It seems that by removing both yarn.lock and node_modules and then yarn install, Truffle packages get deduped.

image

But this solution might be risky, since we might break some dependencies compatibility.

Reducing bundle size by removing Source Maps

Source maps generation was also interfering with bundle size. PR #268 removes source maps altogether from production bundle.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Epic needs investigated refactor Improve code or project quality
Projects
None yet
Development

No branches or pull requests

1 participant