facebook / facebook/hermes

HUGE performance issues with `ethers` (crypto, ArrayBuffer, ...)

Open
#626 11 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
11.3k
Forks
859
Avg merge
1h 30m
Merged PRs (30d)
3

Description

## Bug Description

Using the [ethers.js library](https://docs.ethers.io/v4/cookbook-react.html#shims) is **extremely** slow on Hermes.

On my iPhone 11 Pro (very new and fast phone!) it takes: **half a minute** to create a new wallet:

```
[16:49:19.253] 💰 Creating new Wallet...
[16:49:52.812] 💰 New wallet created! Took 33559.440958321095ms, Phrase: ...
```

Whereas it takes "only" 14 seconds on JSC:

```
[16:56:18.408] 💰 Creating new Wallet...
[16:56:32.854] 💰 New wallet created! Took 14446.050416648388ms, Phrase: ...
```

And while JSC is twice as fast as Hermes, this is still extremely slow!

Reproduceable Code:

```ts
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}`,
)
```

I believe it's one of the polyfills from `@ethersproject/shims` that's causing this huge slowdown. I'd love to find out how this performs without polyfills - that library needs native support for:

* `ArrayBuffer.isView`
* `atob` and `btoa`
* `nextTick`
* `Promise`
* `String.prototype.normalize`
* `FileReader.prototype.readAsArrayBuffer`

As far as I know, `ArrayBuffer.isView` is supported by Hermes, `Promise` is polyfilled by React Native, and `String.prototype.normalize` is not used for `createWallet` (not sure about that)

- [x] I have disabled Hermes in Podfile, re-ran `pod install` and confirmed this bug does not occur with JSC

Hermes version: 0.9.0
React Native version (if any): 0.66.1
OS version (if any): iOS 15.0
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a (I believe?)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.