Reduce Bundle Size
dawsbot opened this issue · comments
Hey Paul, love what you're doing here. I was hoping to switch from sha3
to this in-order to save on bundle size.
Unfortunately the keccak_256
import from noble appears to be 2x the size of the sha3
import from the sha3
library. Before I go into the code to investigate, do you know why this might be?
import { keccak_256 } from '@noble/hashes/sha3';
versus
import { Keccak } from 'sha3';
Hi. I'm not really sure, everything is as minimal as possible.
@dawsbot can you provide both files (bundled noble/sha3 and bundled sha3) as a gist?
@paulmillr good question, I'm not sure which bundle system to use to test this in isolation. I tested this over in essential-eth by replacing the use of sha3
then rerun the whole build process.
What bundling system did you use to get "SHA256-only is 240 lines / 3KB gzipped ?" noted in the readme?
Rollup - see this file https://github.com/paulmillr/noble-hashes/blob/main/rollup.js, you can comment-out unused code
I need more help to do this.
I tested exporting only sha3
via "export * from 'sha3'
" using your rollup config and found it was about 700 bytes. When looking in, I noticed that it had require
s to files which were not in the rollup. I know I don't understand rollup well and have never used it for a project so I'll have to stop here and ask advice.
Any tips?
The sha3 repo has the code public, it's very small: https://github.com/phusion/node-sha3/tree/main/src
you should do npn run build && npm run build:release
. Also do not use the star import, use whatever was specified in this rollup config file. Paste the result file into a gist.
Hey Paul, I don't want to spend the time to take care of this. Feel free to close this if you don't want to take it on.
You haven't provided any build artifacts, so I assume something wasn't configured in a proper way.