Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON.stringify() is 3x slower on Hermes than JSC #1008

Open
summer-wu opened this issue May 23, 2023 · 11 comments
Open

JSON.stringify() is 3x slower on Hermes than JSC #1008

summer-wu opened this issue May 23, 2023 · 11 comments
Labels
enhancement New feature or request performance

Comments

@summer-wu
Copy link

Bug Description

JSON.stringify() is 3x slower on Hermes than JSC.

----hermes
Running JSON.stringify 1000 times cost 7265ms
----jsc
Running JSON.stringify 1000 times cost 1612ms
----node
Running JSON.stringify 1000 times cost 2911ms

Hermes version: 0.11.0
React Native version (if any):0.68.8
OS version (if any): Mac OS 13.3
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): x86_64

Steps To Reproduce

My testing/benchmarking code: https://gist.github.com/summer-wu/030bd287f8a973d66ff1aa71d7e07569

The Expected Behavior

The performance should be similar.

My opinion

Hermes is good at fast-startup, and provides a easy to use debugger(in Flipper).
But when facing some CPU-intensive tasks, it is slower than JSC. For JSON operation, it is 3x slower(JSON.parse is also slower than JSC #811). For RegExp, it is 10x-20x slower(this is why intl polyfill is slow, #495).
Enabling Hermes is worthy when you need a more quick development cycle, but be aware of those drawbacks

@summer-wu summer-wu added the bug Something isn't working label May 23, 2023
@tmikov tmikov added enhancement New feature or request performance and removed bug Something isn't working labels May 23, 2023
@tmikov
Copy link
Contributor

tmikov commented May 23, 2023

Thank you for reporting this. We will look into it.

Can you also provide a report for the RegExp slowness?

@tmikov
Copy link
Contributor

tmikov commented May 24, 2023

Update: we have an internal change that speeds up JSON.stringify() by 2x, so it is only slightly slower than v8. We will publish it soon.

@avp
Copy link
Contributor

avp commented May 26, 2023

8fd20f2 improves the performance of JSON.stringify by about 2x on the benchmark.

@tmikov
Copy link
Contributor

tmikov commented May 26, 2023

Leaving the task open, since we could still improve further to match JSC.

@lucaswitch
Copy link

lucaswitch commented Aug 1, 2023

We are still having this issue on production with Hermes enabled. Our application is a offline first app.It loads/send a heavy load of JSON structures in order to work offline

In heavy use it JSON.stringify 1mb JSON every 15 seconds.
On first first install JSON.parse 30mb of JSON data.

The fix was downgrade to JSC engine.
Version: 0.71.3

@tmikov
Copy link
Contributor

tmikov commented Aug 2, 2023

@lucaswitch RN still hasn't released a version that includes the latest Hermes improvements. Even RN 0.72 includes a version of Hermes from March.

The good news is that we are planning to move to a stable Hermes ABI - when that happens you will be able to drop newer versions of Hermes in your project without waiting for the next RN release.

The bad news is that for now you need to wait for the next RN release to get the latest improvements, or perhaps for a RN point release to backport them.

@neildhar
Copy link
Contributor

neildhar commented Aug 2, 2023

@lucaswitch While the JSON.parse improvements made for #811 have been included in 0.71, the JSON.stringify optimisation in 8fd20f2 is not. You can request a pick for the optimisation into the next point release here: reactwg/react-native-releases#78

@vksgautam1986
Copy link

vksgautam1986 commented Feb 9, 2024

can we have this commit in the main branch for the hermas? -- 8fd20f2
as in react native we are having performance issue and RN team asked to have this in main branch for hermas
reactwg/react-native-releases#98 (comment)

@tmikov
Copy link
Contributor

tmikov commented Feb 9, 2024

Yes, we will port it.

@tmikov
Copy link
Contributor

tmikov commented Feb 11, 2024

@vksgautam1986 6286470

@vksgautam1986
Copy link

thanks @tmikov , you guys are best. Looking forward for static hermas as well in future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

6 participants