Goksu Toprak pfp
Goksu Toprak
@gt
Looking for recommendations on improving the performance of importing wallets on React Native. Using Viem / Ox — Getting 1500ms from `mnemonicToAccount`: https://viem.sh/docs/accounts/local/mnemonicToAccount#mnemonictoaccount Getting 300ms from `privateKeyToAccount`: https://viem.sh/docs/accounts/local/privateKeyToAccount#privatekeytoaccount Looking for pointers to get either of these calls to at most 100ms. Understand that these are optimized in web / node / crypto context but not on React Native yet.
4 replies
4 recasts
31 reactions

Goksu Toprak pfp
Goksu Toprak
@gt
More context: Today Farcaster app uses a combination of other packages (primarily Ethers) and hand rolled a wallet import that takes ~50ms. We want to remove some of these dependencies and fully move to Viem (as it is awesome).
1 reply
0 recast
13 reactions

Frederik Bolding 🦊 pfp
Frederik Bolding 🦊
@frederik
Most likely the bottleneck is PBKDF2 when deriving the mnemonic seed. Most libraries use noble packages without much configurability to swap to native code. We've built an abstraction on top of noble at MetaMask that also supports using native code for PBKDF2: https://github.com/MetaMask/key-tree In combination with something like `react-native-quick-crypto`, that may give a big speed boost! Let me know if you want more details!
2 replies
0 recast
4 reactions

Paul Miller pfp
Paul Miller
@paulm
1. That's pbkdf2. Overall pbkdf is supposed to be slow (100-300ms is norm), BUT mnemonicToAccount bip39 uses 2048 iterations. 2048 iters take 4ms on m4 mac, on older iphones maybe 15ms. Shit androids maybe 50ms. Definitely not noble issue. -- perhaps RN fucks up somewhere. I will take a look at optimizations. 2. privateKeyToAccount's first call calculates precomputes (20-30ms on mac). After that it's very fast. You can either reduce precompute window, or do precompute calc on the app start. cc @frederik @jxom
0 reply
0 recast
1 reaction

Kasra Rahjerdi pfp
Kasra Rahjerdi
@jc4p
i’d build a RN bridge around https://github.com/trustwallet/wallet-core which should make it 10-50x faster right off the bat
1 reply
0 recast
1 reaction