Daniel Lemire published an analysis of Go’s new JSON API. It compares the new and previous JSON encoding and decoding mechanisms.
In Go 1.27, the encoding/json/v2 package is available by default in the standard library. The new API does not directly replace the old one because of differences in Unicode validation and case sensitivity.
When decoding into any, encoding/json/v2 was 1.5–2.3 times faster than the original implementation. When encoding into any, the new API was 1.2–3 times faster.
For typed structures, the new API sped up decoding. When encoding such structures, the old API with the old engine was faster, while the new API was about 1.5 times slower.
Claim check:
- Daniel Lemire published an analysis of the performance of Go’s new JSON API. It compares the new and old JSON encoding and decoding mechanisms. (confirmed by the publication itself: evidence; «The new Go JSON API: twice as fast, or 1.5x slower?»)
- In Go 1.27, the encoding/json/v2 package is available by default in the standard library. (confirmed by the publication itself: evidence; «Go 1.27 makes a new JSON package ( encoding/json/v2 ) available by default in its standard library.»)
- The new API is not a direct replacement for the old one because they differ, including in Unicode validation and case sensitivity. (confirmed by the publication itself: evidence; «The two are not directly comparable as they differ with respect to Unicode validation, case sensitivity, etc. So it is not a drop-in replacement.»)
- The author measured performance on Apple M4 Max and Intel Xeon Gold 6548N in Go 1.27.0, on one core, and reported the median of eight runs. (confirmed by the publication itself: evidence; «I ran this on an Apple M4 Max and on an Intel Xeon Gold 6548N (Emerald Rapids) using Go 1.27.0, on a single core ( GOMAXPROCS=1 ), reporting the median of eight runs.»)
- In tests decoding into any, encoding/json/v2 was 1.5–2.3 times faster than the original implementation for unmarshal and 1.2–3 times faster for marshal. (confirmed by the publication itself: evidence; «Compared to the original implementation, encoding/json/v2 unmarshals 1.5x to 2.3x faster and marshals 1.2x to 3x faster.»)
- For typed structures, the author’s measurements showed that the new API sped up unmarshal, but the old API with the old engine was faster for marshal. (confirmed by the publication itself: evidence; «I still get faster unmarshalling with the new API, but the legacy API with the legacy engine is faster when marshalling.»)
- The author concludes that for typed structures, marshal with the new API was about 1.5 times slower in his tests. (confirmed by the publication itself: evidence; «So unmarshalling gets faster across the board with encoding/json/v2 , and marshalling gets faster for any , but it is about 1.5x slower for typed structs in my tests.»)
Primary sources:
score 64.9 · kind research · revision 1 · stories st-1yp1xc7