Swap json.Unmarshal with jsoniter.Unmarshal #315
Closed
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.
I was looking into some OOMs for this plugin as part of my on call shift and noticed that we are using the standard json package. My understanding is that in grafana/grafana we have switched to using jsoniter in several places because it is at least in theory more performant.
I did a benchmark test here and noticed that jsoniter uses significantly less memory (in these test examples anyway) for Unmarshal...but oddly performed worse for Marshal.
So I made a little package to use whichever one is more performant at the time. But maybe this is overkill and we'd rather just use jsoniter directly and no need for the various performance tests. Btw I used cursor on this and am not a memory usage or bench testing expert so definitely let me know if I'm missing anything!
a note: it might be interesting to add more realistic test cases here if you have them to see if it is indeed more performant... feel free to take over this pr and do with it whatever calls to you and/or disregard but use it for inspiration. I think after this it might be interesting to start putting size limits but that feels worth discussing as a team potentially with product as I'm not sure what a reasonable limit here would be. But if you want a code example of reading size limits I have linked one in the ticket below:
relates to: https://github.com/grafana/data-sources/issues/50