Optimize `JsonNodeDeserialization` wrt recursion
See original GitHub issue(note: cleaved off of #2816, used to be bundled)
Current implementation JsonNodeDeserialization
is expensive for deeply nested Object and Array values as it uses recursion: so for each small additional nesting level – for arrays, 2 bytes to encode [
and ]
– a new stack frame gets created.
In practical terms this means that it is possible to exhaust JVM heap usage with document that has nesting in order of ten thousand(s) levels, depending on settings.
It should be possible to replace basic recursion, however, with iteration, to at least significantly reduce amplification: to prevent cheapest potential DoS concerns.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Deserialize recursive JSON object [closed] - Stack Overflow
I am trying to build a wpf application using mvvm pattern, would like to deserialize the json file recursively.
Read more >Deeply Nested JSON Deserialization Using Recursion and ...
Therefore, I propose an alternative for the use of ExpandoObject to hold inner dictionaries by making use of Method Recursion. Using the Code....
Read more >Allow increasing recursion limit · Issue #334 · serde-rs/json
I am parsing/serializing pretty large JSON files and I regularly encounter RecursionLimitExceeded . I need a way to instantiate a Serializer ...
Read more >Using JSON.stringify() Replacer Function To Recursively ...
Ben Nadel demonstrates how the JSON.stringify() "replacer" function can be used to recursively serialize and sanitize log data.
Read more >How to Flatten Deeply Nested JSON Objects in Non ...
It is dangerous to flatten deeply nested JSON objects with a recursive python solution. Because the python interpreter limits the depth of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can’t say that, it’s tatu’s decision.
However I’m not convinced a depth limit would help with “long texts take a long time to parse” completely. In general you can also allocate a lot of objects without very deep json, e.g.
[[[... 4000 levels...]],[[... 4000 levels...]],... thousands of repetitions...]
. This will not run into the depth limits, but will still be fairly slow to parse (simply because there’s lots of tokens).There is one problem that is unique to deeply nested json in particular (as opposed to other ways of getting many tokens): This line limits the expansion of the
ContainerStack
to max 4000 elements, which means that you can get quite large allocations for every 4000 tokens. However there are always at most two of these arrays alive at a time, so it should not lead to overly large memory use, so it should not be a security risk. It does however reduce perf of parsing of that particular document.@cowtowncoder yes sure https://github.com/FasterXML/jackson-databind/issues/3447