Skip to content

JSON.parse() performance #811

@scarlac

Description

@scarlac

Bug Description

TL;DR: JSON.parse() is 3x slower on Hermes than JSC.

| Engine                  | Method                 | Result |
|-------------------------+------------------------+--------|
| Hermes v0.12.0          | parseJson median       |   50.0 |
| Hermes v0.12.0          | parseJson avg          |   54.5 |
| JSC                     | parseJson median       |   15.0 |
| JSC                     | parseJson avg          |   16.6 |
| NodeJS v16.13.2         | parseJson median       |   15.0 |
| NodeJS v16.13.2         | parseJson avg          |   15.4 |

Porting a React Native app to use Hermes can cause performance regressions depending on use case.
I have narrowed it down to large JSON payloads being loaded. Specifically, JSON.parse() is much slower in Hermes than JSC. JSC is 70% faster than Hermes / Hermes is ~3x slower than JSC. This is significant for our use case and blocks us from migrating.

It's probably fair to say that parsing JSON data from a string is a very common use case. The performance regression (compared to JSC) is severe enough that we cannot use Hermes in production. We have tried 3 times and gotten complaints from users.

  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes version: v0.12.0
React Native version (if any): 0.68.2
OS version (if any): Android 12.0
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a

Steps To Reproduce

  1. Call JSON.parse(largePayloadString)
  2. Compare with JavaScriptCore and NodeJS

Code Example:

https://github.com/scarlac/benchmark-fs#command-line-test-cli-testjs

The repo contains several performance tests but for the purpose of this ticket, we should focus on the cli-test.js file which can be run with the Hermes CLI tool:
hermes cli-test.js

NodeJS performs similar to JSC. It'd be amazing to have Hermes at that level as well.

The Expected Behavior

Performance should be similar (🤞 or better) than JSC.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions