Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle size optimisation based on NYC #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidyuk
Copy link

@davidyuk davidyuk commented Dec 19, 2022

As a workaround to #6 I'm proposing to use a code coverage tool to detect unused functions in the bundle and remove them later. I've managed to reduce minified bundle size from 6.95mb to 2.15mb keeping the required functionality.

related to aeternity/aepp-sdk-js#1117 aeternity/aepp-sdk-js#1693

This PR is supported by the Æternity Crypto Foundation

$ ./optimise.sh 
+ mkdir -p temp
+ sed 's/\t/  /g' ../dist/bundle.js
+ node ./src/test.js
Looks ok
+ npx webpack
asset output.js 6.95 MiB [emitted] [minimized] (name: main)
cacheable modules 11.7 MiB
  ./src/test.js 7.86 KiB [built] [code generated]
  ./temp/bundle.js 11.7 MiB [built] [code generated]
external "fs/promises" 42 bytes [built] [code generated]
external "crypto" 42 bytes [built] [code generated]
external "buffer" 42 bytes [built] [code generated]
webpack 5.75.0 compiled successfully in 66356 ms
+ node ./temp/output.js
Looks ok
+ rm -rf ../.nyc_output
+ NODE_OPTIONS=--max-old-space-size=6000
+ npx nyc node ./src/test.js
Looks ok
------------|---------|----------|---------|---------|------------------------------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                              
------------|---------|----------|---------|---------|------------------------------------------------
All files   |   14.96 |     8.39 |   25.87 |   43.37 |                                                
 src        |      50 |    29.26 |   61.53 |   56.09 |                                                
  test.js   |      50 |    29.26 |   61.53 |   56.09 | 37-75,83-84,92,109-110                         
 temp       |   14.94 |     8.38 |   25.83 |   43.08 |                                                
  bundle.js |   14.94 |     8.38 |   25.83 |   43.08 | ...960,6967-6985,6993-7004,7014-7017,7025-7027 
------------|---------|----------|---------|---------|------------------------------------------------
+ node remove-unused.mjs
+ npx webpack
asset output.js 2.28 MiB [emitted] [minimized] (name: main)
cacheable modules 5.49 MiB
  ./src/test.js 7.86 KiB [built] [code generated]
  ./temp/bundle.js 5.49 MiB [built] [code generated]
external "fs/promises" 42 bytes [built] [code generated]
external "crypto" 42 bytes [built] [code generated]
external "buffer" 42 bytes [built] [code generated]
webpack 5.75.0 compiled successfully in 21771 ms
+ node ./temp/output.js
Looks ok
+ npx google-closure-compiler --js ./temp/bundle.js --js_output_file ./temp/bundle-out.js
+ mv ./temp/bundle-out.js ./temp/bundle.js
+ npx webpack
asset output.js 2.15 MiB [emitted] [minimized] (name: main)
cacheable modules 2.2 MiB
  ./src/test.js 7.86 KiB [built] [code generated]
  ./temp/bundle.js 2.19 MiB [built] [code generated]
external "fs/promises" 42 bytes [built] [code generated]
external "crypto" 42 bytes [built] [code generated]
external "buffer" 42 bytes [built] [code generated]
webpack 5.75.0 compiled successfully in 20662 ms
+ node ./temp/output.js
Looks ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants