React Native: Solutions for slow crypto-operations (`Wallet.createRandom()`)
See original GitHub issueA lot of issues have been opened about React Native being slow. For example, creating a wallet takes 33 seconds on an iPhone 11 Pro - I don’t even want to find out how slow that is on an older Android device.
This code:
import 'react-native-get-random-values'
import '@ethersproject/shims'
import { ethers } from 'ethers'
const now = performance.now()
Logger.log('💰 Creating new Wallet...')
const wallet = ethers.Wallet.createRandom()
const end = performance.now()
Logger.log(
`💰 New wallet created! Took ${end - now}ms, Phrase: ${wallet.mnemonic.phrase}`,
)
Takes half a minute:
[16:49:19.253] 💰 Creating new Wallet...
[16:49:52.812] 💰 New wallet created! Took 33559.440958321095ms, Phrase: ...
I’m wondering if there is any workaround to make this code faster, as it’s definitely not a solution to let the user wait for 5 minutes until he can use the app.
I can create a library for the crypto polyfills that uses a pure C/C++ implementation accessed synchronously through JSI for maximum performance, but I’d need help to find out what algorithms are slow and where I can swap them.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:43 (4 by maintainers)
Top Results From Across the Web
React Native slow / freeze whet i call ethers.Wallet ...
I have test this in both IOS and Android and was able to create a HD Wallet instantly. To use bip39 in React...
Read more >Ethers.js function createRandom() is too slow when ...
I figured out that the createRandom() function is too slow because it is also creating a mnemonic of the private key. The solution...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you have an ETA for v6?
I did it.
@zemse @mirceanis @ricmoo how do I swap the pbkdf2 function?
The one from this library takes 14 seconds:
and my pure C++ JSI implementation takes 0.001 second:
…so it’s almost 10.000x faster.
I’d love to make that open source if there’s a way to swap the implementations.