-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: map[string]interface performance #35585
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
Comments
Why is the encoding/decoding performance of maps important here? Usually, when one is decoding large amounts of data, structs are used. It seems to me like gojay makes types like maps more efficient by adding more code to handle them especially. It's something we can consider, but it's a tradeoff. We don't want the standard library to get large in size, and hard to maintain. Do you have a realistic piece of code where the peformance here is a problem, or is this simply about benchmarking different json libraries? |
We use maps to store data in our data model. The map is used to allow queries in Kibana - kibana does not support query for nested objet array. |
I see, thanks. If someone wants to experiment with this, I'll be happy to review the code. There might be low hanging fruit to remove an alloc or two in some cases. |
It looks like gojay avoids allocating by unsafely converting the []byte input to a string. This is not a condition encoding/json imposes on its callers, nor can it start. So this particular "optimization" ("bug" might be more likely) is not available. Gojay also seems to be accidentally quadratic in its unescaping of strings, for what it's worth. I'm not sure there's anything actionable in this issue. |
Closing as this doesn’t seem actionable. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Benchmark JSON marshaling and unmarshaling for
encoding/json
, gojay, jsoninter, fastjson. The performance of stdlib is overall similar to other 3rd party libraries. However, marshaling produces substantially more allocations than gojay library formap[string]interface{}
and two times ns/op.For unmarshaling the allocations by gojay are 30% lower (my number not amount) and ns/op half time of stdlib.
marshaling:
unmarshaling
Benchmarks and results are here https://github.com/pavolloffay/golang-json-benchmark
What did you expect to see?
encoding/json
the same performance as https://github.com/francoispqt/gojayWhat did you see instead?
encoding/json
is slower than https://github.com/francoispqt/gojay for marshalingmap[string]interface{}
and for unmarshaling it produces more allocations and is 2 times slower on ns/op.The text was updated successfully, but these errors were encountered: