perf(json): address performance penalty found in v0.4.0+ #149
+35
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of #137, a new helper function
decodeInto
was introduced that used generics and was added into the decode path for objects, arrays, strings and numbers.Unfortunately, this seems to have introduced a pretty severe memory penalty for one of our internal services, showing at least a significant increase of memory heap allocations (>30% in a testing environment) when decoding
map[string]any
values.For the last few years, we've actually just stayed pinned to v0.3.6, but now we're being pulled forward by other dependency updates and need to have this addressed.
Once isolating the root cause to this particular helper function, I added some more benchmarks to cover this situation and did a comparison between the current "main.txt" and this proposed "branch.txt":
In short, reverting the object/array/string decode logic back to what it was previously, we get pretty significant improvements across the board.
Since the main point of #137 was about that number decoding, I decided to leave that alone as we are not using this and do not presume the performance characteristics, but the rest of the changes seemed like fair game to revert.