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

bn: use BigInt function over literals #33

Closed
wants to merge 1 commit into from

Conversation

tynes
Copy link
Member

@tynes tynes commented Sep 6, 2019

Replace all BigInt literals with BigInt functions.

This will allow the Node.js application bundles to be uglified and save some space on the size of the package. All code ran from the base directory of the bcoin gitrepo.

# without these changes, cannot use uglify-es
$ bpkg bin/node -o bcoin
$ du -h bcoin
5.3M

# with these changes, uglify-es installed globally
$ bpkg bin/node | uglifyjs > bcoin
$ du -h bcoin
4.3M

# with one additional change, removing the #!/usr/bin/env node
# this breaks the parser in bpkg/vendor/uglify-es
$ bpkg -p [ uglify-es ] bin/node -o bcoin
$ du -h bcoin
3.9M

# doing a release does uglify each file after this change
# no problems with #! like seen above
$ bpkg -p [ uglify-es ] -m -o $HOME/bcoin

Using BigInt functions over literals saves ~20% on the total package size in the end. With likely bcoin and hsd releases soon, the stylistic changes may be worth it. If you prefer the style using BigInt literals, we may need to implement our own uglifyjs that has an up to date parser. This commit can be reverted in the future when JS tooling catches up with the latest language features.

Note that when building for frontend, if the parser does not support BigInt literals, it should still be possible to build if the correct environment variable is present, NODE_BACKEND=js. Noting this here so that people can find it in the future.

Closes #32
Closes #14

@deanpress
Copy link

Is this going to be merged? Our front-end application has experienced the same issues due to this (not loading in Safari) and have so far been unable to fix it with NODE_BACKEND=js.

@tynes
Copy link
Member Author

tynes commented Jan 26, 2020

@deanpress The node backend has been removed on the latest branch. https://github.com/bcoin-org/bcrypto/tree/torsion/lib

There isn't a way to ignore files when bundling? And bundlers still can't handle the new syntax?

@tynes
Copy link
Member Author

tynes commented Jan 27, 2020

Closing as this is no longer relevant

@tynes tynes closed this Jan 27, 2020
@deanpress
Copy link

@deanpress The node backend has been removed on the latest branch. https://github.com/bcoin-org/bcrypto/tree/torsion/lib

There isn't a way to ignore files when bundling? And bundlers still can't handle the new syntax?

Cheers!

Yes, I currently have it set up to ignore the node version by setting the env var and bundling the package using WebpackIgnorePlugin(), which works.

freedomhero added a commit to sCrypt-Inc/scryptlib that referenced this pull request Mar 17, 2021
freedomhero added a commit to sCrypt-Inc/scryptlib that referenced this pull request Mar 17, 2021
* ignore fs & child_process in browser env

* use BigInt function over literals to allow third party using bable / uglifyjs etc.

Ref: bcoin-org/bcrypto#33

* add timeout option for compile function

* bump version to 0.3.2
zhfnjust pushed a commit to sCrypt-Inc/scryptlib that referenced this pull request Mar 20, 2021
* ignore fs & child_process in browser env

* use BigInt function over literals to allow third party using bable / uglifyjs etc.

Ref: bcoin-org/bcrypto#33

* add timeout option for compile function

* bump version to 0.3.2
zhfnjust pushed a commit to sCrypt-Inc/scryptlib that referenced this pull request Mar 24, 2021
* ignore fs & child_process in browser env

* use BigInt function over literals to allow third party using bable / uglifyjs etc.

Ref: bcoin-org/bcrypto#33

* add timeout option for compile function

* bump version to 0.3.2
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.

BigInt function vs BigInt literals WARNING: Identifier directly after number
2 participants