-
Notifications
You must be signed in to change notification settings - Fork 911
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
fix: eliminate bn.js and replace public key storage with JavaScript bigint
#1142
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1142 +/- ##
==========================================
- Coverage 76.35% 76.06% -0.29%
==========================================
Files 56 56
Lines 3151 3159 +8
Branches 475 481 +6
==========================================
- Hits 2406 2403 -3
- Misses 578 585 +7
- Partials 167 171 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
will this break the old concern is that calling a function from a library that uses an older version of |
Most certainly; good call-out. Options:
I'm not sure if 2 would actually ‘work,’ but it does in my head. Thoughts, @joncinque, @jordansexton? |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Problem
JavaScript
bigint
has been available in browsers since September 2020. Despite that we've implemented large value storage inPublicKey
using thebn.js
library. This library presently makes up ~13% of@solana/web3.js
, or around 35K uncompressed.Replacing this system with pure
bigint
storage would cut the size of this library down considerably.Summary of Changes
borsh
to serialize to and frombigint
rather thanBN
instances. A pull request has been sent to the upstream project.BN
storage inPublicKey
withbigint
Bundle size
Using
package-build-stats
:Size before: 75299 gzipped bytes
Size after: 64191 gzipped bytes
Reduction of ~14%.
Notes
PublicKey::_bn
will find that its type has changed fromBN
tobigint
. Such is the risk when you reach into private variables.borsh-js
in a way that represents a breaking change. For this reason we modify the bundle script to bundle the modified version into theweb3.js
bundle. This has two implications:borsh
outside ofweb3.js
will end up bundling a second copy of it (presumably one that includes 'bn.js` which negates the benefits of this change)web3.js
and will not cause a breaking change to the rest of the app.Addresses #1103.