question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native: Solutions for slow crypto-operations (`Wallet.createRandom()`)

See original GitHub issue

A 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: ...

See https://github.com/facebook/hermes/issues/626

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:43 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
mrousavycommented, Nov 2, 2021

Do you have an ETA for v6?

8reactions
mrousavycommented, Oct 31, 2021

I did it.

@zemse @mirceanis @ricmoo how do I swap the pbkdf2 function?

The one from this library takes 14 seconds:

ether's pbkdf2 took 14279.91887497902ms

and my pure C++ JSI implementation takes 0.001 second:

C++ pbkdf2 took 1.4742500185966492ms

…so it’s almost 10.000x faster.

I’d love to make that open source if there’s a way to swap the implementations.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found