-
Notifications
You must be signed in to change notification settings - Fork 22
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
Parsing into Map #49
Comments
In option2,
Does this byte array means For example:
If the second "bytes1" want to get correct result, I think the byte array needs to do save for each "bytes"? However, copy byte array may cost time as much as option1? On one hand, option1 + cache can save parsing times (from x times to 1 time if no cache miss), but the only parsing could be costly, since all Strings are created; On the other hand, option 2 can reduce parsing cost, since no instance of String has been created, but the same JSON string may be parsed more than once. But in the end, I'm convinced by
I vote for option2. |
Optimally would be nice to have the ability to do both, but in SIMD spirit, lazy parsing seems more appropriate, especially once full on stream parsing is eligible, that can be the underlying harness of most things if need be. I think initially option 2 is better, but it should cache the result maybe? I think jackson does this alot and it bodes well. |
@piotrrzysko I agree with @zekronium , Option 2 would be preferred, but even Option 1 a good start. I wonder if we want to use a |
Introduction
Sometimes users want to parse a JSON object into a map.
Let's assume that we have the following example object:
We expect the parser to produce a
Map<String, Object>
from which we should be able to extract the object's fields in the following way:Question
Let’s assume that the parser exposes an API like:
The returned map is immutable.
JSON parsing benchmarks often show that, in Java, creating new strings takes a significant portion of the time. So, the question is: at which stage should this happen? I see two options:
Option 1
Option 2
I suppose the second option is far more efficient in situations where someone wants to access only a small set of all fields and they want to do so only once.
@ZhaiMo15 @zekronium since you reported this topic, what are your thoughts? I’d like to understand your use cases better to be able to choose a more suitable option or come up with something else.
The text was updated successfully, but these errors were encountered: