-
Notifications
You must be signed in to change notification settings - Fork 642
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.parse() performance #811
Comments
I was able to repro this with the file at the link. |
Hi @scarlac, just wanted to update you that the team has started an investigation into this issue. We are optimistic that we can bring perf improvements to JSON.parse, to bring it on par to JSC/V8. We will be entering the experimentation phase soon to see what changes help. We will update this thread as we make progress. I wanted to ask more about the kinds of JSON data you are actually processing. In the benchmark you provided, objects with the same keys & values are being constructed many times. Is that representative of your actual production workload? Do you expect that a lot of the data you are processing will have the same keys or values? If there's any other useful benchmarking tests for JSON parsing you can share, that would be helpful as well. |
@fbmal7 love to hear it. The data we typically parse is more varied and deeper nested but I wanted to make the test case clear and simple to begin with. in reality we see a lot of variety in the values. Eg GUIDs, long lists of photos with local file paths (formatted as a URI), metadata with numbers and strings, product names, etc. |
@fbmal7 One big use case for this is the usage of redux-persist which save and load data from JS to any database we want. This is done a lot of times even if it's throttled |
Summary: Parse plain strings efficiently in JSON.parse. This is one step towards closing the gap in JSON.parse perf of Hermes vs JSC/V8, as noted in [this](#811) GH issue. Reviewed By: jpporto Differential Revision: D40283500 fbshipit-source-id: aa7ac3ee6c05328f7747aed1d7bf7e856ba763a7
Thanks @fbmal7 ! Any improvement we can make to JSON handling is a giant win for almost all apps. I can't think of any that don't use JSON heavily. From API responses to persistence layers, to wonky deep object cloning. |
We don't tend to cut releases for Hermes very often. Building Hermes from source is always an option, and it's not too complicated. If you just want to build hermes and run it on the command line, you can use these instructions. |
Summary: Parse plain strings efficiently in JSON.parse. This is one step towards closing the gap in JSON.parse perf of Hermes vs JSC/V8, as noted in [this](facebook#811) GH issue. Reviewed By: jpporto Differential Revision: D40283500 fbshipit-source-id: aa7ac3ee6c05328f7747aed1d7bf7e856ba763a7
Hi @scarlac, just wanted to update you again. To get better improvements past the simple one we already landed has been a lot more work than initially anticipated. However, I wanted to let you know the team is still looking at this issue! We are exploring optimizations such as:
I'm not too sure on the timeline for all of this, but will keep the thread updated as we make progress. |
Thanks @fbmal7 . I appreciate the details and the team's hard work on this! Sounds like it'll make for some great release notes on the RN blog :) |
@scarlac My favorite thread to update! I'm finally getting around to landing some of the changes I wrote a couple months back. Two optimizations just landed yesterday and will make their way into 0.72. They did not bring as big of a win as the previous optimization.
The next change I have planned is one of the ones I referenced above- only performing expensive hash computation+lookups on strings that are object keys. Currently we are always performing a hash lookup for all strings we are scanning in the parser. We don't differentiate parsing for string keys vs. string values. |
@fbmal7 Love getting these updates. Really impactful for everyone using RN. Thanks again! |
https://twitter.com/radexp/status/1630581333318680577 @radex would be great to hear about your JSON parsing improvements :) |
yes, yes, soon :) |
Here's a proof of concept: #933 |
We're seeing the same issue, reverted back to using JSC for now. Would love to see Hermes performance being on par with JSC. |
We upgraded react native version from 0.69.5 to 0.71.13 and then we just started to get syntax error from JSON.parse(). After deactivating hermes again, the issue is resolved. We could not use hermes in production! |
This doesn't sound related to the performance issue. Can you specify what exactly broke and provide a json snippet or at least the error message? Otherwise it's not possible to investigate. |
This is not a performance issue but I think it should be resolved together. We were trying to parse a data like this: "{"lorem":{"xx_version":"1.0.0.0","yy_version":"1.0.0.1","zz_build":"Jul 17 2022 14:35:23","kk_version":"1","hh_id":"tttt-b-c8a952066002","gg_id":"@XXXXXXX","cc_id":"686725B847A0"}}" After switching to new react native version 0.71.13, we just started to get SyntaxError: Unexpected token ..., although it is in the appropriate format. |
@hakansaglam29 I just tried your example and it parses with Hermes without an error. |
Yes. if you try this output directly, JSON.parse is working. But i am getting this output as a response and using with JSON. parse. After that it throws an error. I could not understand why. But somehow after disabling Hermes, it worked again. |
@hakansaglam29 We can't debug the issue until you provide working repro steps. You should also open a new issue as this doesn't have to do with JSON parsing performance. There could be other polyfills or changes that happen when you switch to Hermes that are actually the root cause of your issue, not |
Thanks @fbmal7 i will open a new issue. |
Bug Description
TL;DR:
JSON.parse()
is 3x slower on Hermes than JSC.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.
gradle clean
and confirmed this bug does not occur with JSCHermes 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
JSON.parse(largePayloadString)
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.
The text was updated successfully, but these errors were encountered: