RFC: partial decoding
I made a proof of concept for this a while back, pushed a branch, and then didn't actually explain what it is: https://github.com/dakrone/cheshire/tree/field-predicate-feature
Basically, we want to be able to use the "skip children" feature in the Jackson parser. Unfortunately, it's hard to specify where to skip without some sort of schema, but schemas (typically) would require us to enumerate all the fields we want to parse, rather than use some sort of programmatic specification.
My questionable workaround for this is a predicate function which passes in the parent and child keys as it traverses the JSON structure. So for this structure:
{"a": {"b": 1}}
The predicate would first get passed [nil "a"] to check if {"b": 1} should be parsed, and then ["a" "b"] to check if the 1 should be parsed. This is an adequate solution, at best, but I can't think of an obviously better one.
The performance gains here are at best 50%, as Jackson still needs to figure out where the children nodes end. However, 50% is still pretty good. I'd be interested to hear your thoughts.
I'll check out the branch, thanks for the reminder!
@ztellman I agree that what the predicate gets passed is a little confusing, but I think for the subset of users that would find this useful, [parent key] will suffice, adding the plumbing for passing the whole parent path would probably add too much overhead to make use of the speed boost from not parsing the child.
I think this looks pretty good to me, want to add some docs for it and then submit a PR (or merge it in since you have commit access)?
any progress on this @ztellman? reinventing the Clojure wrapper in another lazy JSON parse is a pain :-)
Well, it's been a while, but I wasn't very happy with the approach to the predicate and ultimately didn't think it was worth it. If you'd like to pick this up and create a PR against the current codebase, please feel free.
I made a PR with that feature (as far as I understand) #134