-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: replace BN with native BigInt #18473
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
feat: replace BN with native BigInt #18473
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
8042d5e to
d6ddc81
Compare
salimtb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
georgewrmarshall
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving changes to component-library components on behalf of @MetaMask/design-system-engineers ✅
1909901
d6ddc81 to
1909901
Compare
1909901 to
f9738d5
Compare
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
27c55f8 to
6ea5e81
Compare
64d2a07
into
MetaMask:feat/replace-bn-with-bigint-margelo
Description
This draft of migration from BN.js to native
BigInt. It needs MetaMask/utils#255 to be merged and released first.Native BigInt is much much faster than JS only BN implementation. This could improve app performance in many places like account list, login, dashboard etc. I already measured
useAccountshook and it made it 7x faster220ms => 30ms.Proposal for handling migration:
I moved cloned previous file
index.jstolegacy.jsand updated imports everywhere to use this old implementation. Then I migrated whole oldindex.jsto TS and to useBigInt. I also marked all legacy functions as deprecated so they could be spotted more easily during future refactoring and replaced with new implementation.I think this approach is best in current situation because:
any.TODOs:
toHexadecimaland while migrating it to new implementation with bigint I noticed that i receives params likesolana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp. In old implementation it causestoHexadecimal returnNaNand in my new implementation it throws error. I guess this might be causing bug even in current implementation like total balance not being correct if there is more than one Solana account or something like that.Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduce BigInt-backed number utilities while re-pointing existing code to legacy implementations, updating balance/fee logic and tests accordingly.
util/number/index.tswith BigInt-based conversions/formatting (hexToBigInt,bigIntToHex,toWei,fromWei, fiat/token helpers, etc.).util/number/legacy.js(marked deprecated) and add comprehensivelegacy.test.ts.BigInt.util/numberwithutil/number/legacyacross app (Swaps, Ramp, Earn, Stake, Bridge, Transactions, selectors, hooks, components, tests).Hexcast, tweak chainId handling for images/selectors).hexToBigInt,bigIntmath) and avoid string BN math; fix chainId map lookups (use rawchainId).0xprefix.Written by Cursor Bugbot for commit 6ea5e81. This will update automatically on new commits. Configure here.