Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upencoding/json: map[string]interface performance #35585
Comments
This comment has been minimized.
This comment has been minimized.
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? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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.