qgustavor / tweetnacl-js

Port of TweetNaCl cryptographic library to JavaScript
https://tweetnacl.js.org
The Unlicense
0 stars 0 forks source link

Some code can't be tree shaken #1

Open qgustavor opened 4 years ago

qgustavor commented 4 years ago

The smallest build that can be generated using this fork is building import 'tweetnacl': it returns a 0.48KB gzip / 0.42KB brotli file containing those variable initiations and PRNG initilization.

At the moment this remaining unused unshakeable code is too small so I can accept it, in the other hand, would be great if someone have a solution to make this code tree shakeable too.

qgustavor commented 4 years ago

Adding /*#__PURE__*/ before gf() calls makes Rollup remove this code when it's not used. This line isn't removed using this annotation, but it gets removed if rewritten to new Uint8Array([9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).

I could not find any way to make Rollup remove the CSPRNG initialization IIFE when randombytes is never called. Seems that it's too complex for this tool. In the other hand seems it removes most of the IIFE.

I will keep this issue open for the discussion. In future (possibility the next time I build something using this library) I will update it with the above changes.