hermes
hermes copied to clipboard
JSON.stringify() is 3x slower on Hermes than JSC
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
Thank you for reporting this. We will look into it.
Can you also provide a report for the RegExp slowness?
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.
https://github.com/facebook/hermes/commit/8fd20f29af83ab59c5e21d7de8212bcc904dcc4a improves the performance of JSON.stringify
by about 2x on the benchmark.
Leaving the task open, since we could still improve further to match JSC.
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
@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.
@lucaswitch While the JSON.parse improvements made for #811 have been included in 0.71, the JSON.stringify optimisation in 8fd20f29af83ab59c5e21d7de8212bcc904dcc4a is not. You can request a pick for the optimisation into the next point release here: https://github.com/reactwg/react-native-releases/discussions/78
can we have this commit in the main branch for the hermas? -- https://github.com/facebook/hermes/commit/8fd20f29af83ab59c5e21d7de8212bcc904dcc4a as in react native we are having performance issue and RN team asked to have this in main branch for hermas https://github.com/reactwg/react-native-releases/discussions/98#discussioncomment-8057686
Yes, we will port it.
@vksgautam1986 https://github.com/facebook/hermes/commit/628647010420d988ec4a08ec63742904c4bc785a
thanks @tmikov , you guys are best. Looking forward for static hermas as well in future