-
Notifications
You must be signed in to change notification settings - Fork 154
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
Treeshaking not working with maci library packages #781
Comments
I'm gonna try a few things and see what we can do to address this. For |
Wow thanks for reporting this @yuetloo (& for the investigation)! |
(using maci npm package: 0.0.0-ci.45668db) (previous version of maci v1) @0xmad @ctrlc03 it looks like something else in the current MACI dev branch has increased the bundle size, not sure what it is because there's a lot of changes in the current MACI dev branch since clrfund cloned the MACI v1 branch. However, moving |
I think it's related to tests and source folders. We need to build bundle with separate tsconfig instead of using only one which includes all the ts code needed for development. |
@yuetloo new version is published. |
@samajammin it should. If @yuetloo is ok with this fix we can close this issue. |
@yuetloo feel free to reopen it if the fixes don't work for you. |
We noticed that by importing just 1 function (genTallyResultCommitment) from the maci-core library, our web app size would double. Duplicating that function (as opposed to importing from maci-core) would bring the web app size back down.
Here are the sizes of our web app:
(import from maci-core)
7,567.22 kB │ gzip: 3,538.62 kB
(duplicate function locally)
3,669.37 kB │ gzip: 1,726.62 kB
I tried different rollup treeshaking options on our vite.config file, without success.
I tried adding "sideEffects: false" manually in the maci-core package in the local node_modules folder and still not working.
While working on using the snarkjs API, I stumbled onto this issue (iden3/snarkjs#152) which shows that ffjavascript library that maci-crypto depends on has side effects that might be causing treeshaking to not work.
For optimization, ffjavascript uses a global (globalThis variable) to pass back a handle for the consumer to terminate the threads.
Note that maci-crypto only uses the utils functions in (ffjavascript)[https://github.com/privacy-scaling-explorations/maci/blob/dev/crypto/ts/index.ts#L9), may be duplicating those functions instead of
require('ffjavascript
) could reduce the bundle size of app?Also, moving the
genTallyResultCommitment
from maci-core to maci-crypto may help as we only need to import maci-crypto.We use all the hash and encrypt/decrypt functions in maci-crypto to generate key and encrypt/decrypt messages on our web app.
Appreciate any suggestion on what to do to enable treeshaking and reduce our web app size.
The text was updated successfully, but these errors were encountered: