Skip to content

Instantly share code, notes, and snippets.

@Deleplace
Created November 25, 2026 15:25
Show Gist options
  • Select an option

  • Save Deleplace/02334b893ea05e09443c2fa66024f16a to your computer and use it in GitHub Desktop.

Select an option

Save Deleplace/02334b893ea05e09443c2fa66024f16a to your computer and use it in GitHub Desktop.
Benchmark results for go/issues/81315, measured 2026-11-25

Headline: json_test.go:105-111 (Issue #81315 golang/go#81315)

Version legacy (nojsonv2) json (v1 API, v2 backend) jsonv2 (v2 API)
Go 1.27.3 4.298 ms ± 4% (266.1 MiB/s, 2 allocs) 6.995 ms ± 3% (+62.73%, 163.5 MiB/s, 3 allocs) 6.726 ms ± 8% (+56.47%, 170.1 MiB/s, 3 allocs)
Go tip (396ec8dd36) 4.592 ms ± 5% (249.1 MiB/s, 2 allocs) 5.018 ms ± 6% (+9.27%, 227.9 MiB/s, 2 allocs) 5.192 ms ± 7% (+13.05%, 220.4 MiB/s, 2 allocs)
Tip vs 1.27.3 +6.84% (VM drift; see note) -28.26% (p=0.000, 3 → 2 allocs) -22.81% (p=0.000, 3 → 2 allocs)

• Original observation reproduced: On Go 1.27.3, marshaling the 10k []Record slice is 1.63× (json) / 1.56× (jsonv2) slower than GOEXPERIMENT=nojsonv2, matching Daniel Lemire's ~1.5× slowdown reported in #81315 golang/go#81315. • Major recovery on Go tip: On tip (396ec8dd36), MarshalRecords speeds up by 23%–28% and drops from 3 → 2 allocs/op (matching legacy). The slowdown relative to legacy shrinks from +56%–63% down to +9%–13% (and ~+14%–20% in a quick interleaved check eliminating inter-run VM drift, where legacy was ~4.4–4.6 ms on both versions, json dropped from ~6.9 ms to ~5.1 ms, and jsonv2 dropped from ~7.0 ms to ~5.2 ms). ──────

Full benchstat Comparisons (sec/op, AMD EPYC 7B12, n=8)

1. Go 1.27.3: legacy vs json vs jsonv2

Benchmark legacy (sec/op) json (sec/op) json vs legacy jsonv2 (sec/op) jsonv2 vs legacy
UnmarshalAny/twitter 9.339 ms ± 2% 10.879 ms ± 16% +16.50% (p=0.000) 6.070 ms ± 5% -35.01% (p=0.000)
UnmarshalAny/canada 47.38 ms ± 2% 71.24 ms ± 12% +50.35% (p=0.000) 34.67 ms ± 7% -26.84% (p=0.000)
UnmarshalAny/citm_catalog 25.06 ms ± 3% 25.40 ms ± 6% ~ (p=0.382) 12.89 ms ± 5% -48.57% (p=0.000)
MarshalAny/twitter 6.807 ms ± 4% 4.516 ms ± 31% -33.66% (p=0.000) 2.915 ms ± 11% -57.18% (p=0.000)
MarshalAny/canada 17.82 ms ± 4% 13.49 ms ± 4% -24.27% (p=0.000) 13.23 ms ± 4% -25.78% (p=0.000)
MarshalAny/citm_catalog 10.378 ms ± 2% 6.625 ms ± 4% -36.16% (p=0.000) 5.453 ms ± 5% -47.46% (p=0.000)
UnmarshalRecords 29.65 ms ± 3% 20.29 ms ± 5% -31.56% (p=0.000) 17.60 ms ± 12% -40.66% (p=0.000)
MarshalRecords 4.298 ms ± 4% 6.995 ms ± 3% +62.73% (p=0.000) 6.726 ms ± 8% +56.47% (p=0.000)
geomean 14.33 ms 13.54 ms -5.54% 9.520 ms -33.57%

2. Go tip (396ec8dd36): legacy vs json vs jsonv2

Benchmark legacy (sec/op) json (sec/op) json vs legacy jsonv2 (sec/op) jsonv2 vs legacy
UnmarshalAny/twitter 9.606 ms ± 4% 11.392 ms ± 11% +18.58% (p=0.000) 6.693 ms ± 5% -30.33% (p=0.000)
UnmarshalAny/canada 50.07 ms ± 4% 80.32 ms ± 14% +60.42% (p=0.000) 37.35 ms ± 2% -25.41% (p=0.000)
UnmarshalAny/citm_catalog 27.41 ms ± 3% 25.79 ms ± 9% ~ (p=0.105) 13.47 ms ± 3% -50.85% (p=0.000)
MarshalAny/twitter 7.155 ms ± 7% 4.720 ms ± 4% -34.02% (p=0.000) 3.162 ms ± 6% -55.80% (p=0.000)
MarshalAny/canada 17.92 ms ± 3% 12.54 ms ± 3% -30.04% (p=0.000) 12.47 ms ± 3% -30.43% (p=0.000)
MarshalAny/citm_catalog 11.682 ms ± 3% 6.679 ms ± 7% -42.83% (p=0.000) 5.550 ms ± 4% -52.49% (p=0.000)
UnmarshalRecords 31.64 ms ± 5% 18.14 ms ± 3% -42.67% (p=0.000) 15.74 ms ± 3% -50.26% (p=0.000)
MarshalRecords 4.592 ms ± 5% 5.018 ms ± 6% +9.27% (p=0.000) 5.192 ms ± 7% +13.05% (p=0.000)
geomean 15.21 ms 13.07 ms -14.12% 9.386 ms -38.31%

Across all 8 core benchmarks, the geomean vs legacy improved from -5.54% to -14.12% for json (v1 API) and from -33.57% to -38.31% for jsonv2.

3. Go 1.27.3 vs Go tip Highlights (including tune_test.go)

Benchmark Go 1.27.3 (sec/op, allocs) Go tip (sec/op, allocs) Time Δ Allocs Δ
MarshalRecords/json 6.995 ms, 3 5.018 ms, 2 -28.26% -33.3%
MarshalRecords/jsonv2 6.726 ms, 3 5.192 ms, 2 -22.81% -33.3%
MarshalRecordsTuned/v2 6.679 ms, 4 5.252 ms, 3 -21.36% -25.0%
MarshalRecordsTuned/v2+utf8 7.129 ms, 4 5.310 ms, 3 -25.51% -25.0%
MarshalRecordsTuned/v2+dup 6.730 ms, 4 5.268 ms, 3 -21.72% -25.0%
MarshalRecordsTuned/v2+utf8+dup 6.642 ms, 4 5.330 ms, 3 -19.75% -25.0%
MarshalRecordsTuned/v2-MarshalWrite-reusebuf 6.115 ms, 3 (72 B) 5.370 ms, 2 (48 B) -12.19% -33.3%
MarshalRecordsTuned/v2-MarshalEncode-reuseenc 6.164 ms, 3 (72 B) 5.341 ms, 2 (48 B) -13.35% -33.3%
UnmarshalRecords/json 20.29 ms, 50.21k 18.14 ms, 50.21k -10.61% ~
UnmarshalRecords/jsonv2 17.60 ms, 50.21k 15.74 ms, 50.21k -10.56% ~
MarshalAny/json/canada 13.49 ms, 9 12.54 ms, 6 -7.10% -33.3%
MarshalAny/jsonv2/citm_catalog 5.453 ms, 16 5.550 ms, 4 ~ -75.0%

Note on cross-run VM drift: Between the two separate ~6.5-minute benchmark windows on this shared cloudtop VM, even unchanged control benchmarks (legacy geomean +6.16%, handwritten-reusebuf +7.89%) drifted ~6–8% slower during the tip window, which also accounts for the apparent small +5%–15% upticks on UnmarshalAny/jsonv2/* and MarshalRecordsTuned/v2-MarshalJSONTo*. The MarshalRecords (-23% to -28%) and UnmarshalRecords (-10.6%) gains on Go tip are well above that noise floor (and were confirmed by an interleaved back-to-back check).

──────

Why This Matches Issue #81315 golang/go#81315 Current Status

Checking git log in go:

  • Already merged in tip (396ec8dd36):
    • d93b69fd69 — lazily copy unaddressable values for marshaling (explains the -1 alloc/op and 72 → 48 B/op drop on MarshalRecords and 33–75% fewer allocs on MarshalAny)
    • 9dd31ba8ff — avoid redundant buffer stores in jsontext/v2
    • 89b15e2635 & 566901ccdb — avoid inlining struct/additional arshaler construction
    • 35455b81d3, b5046c0358, c88aced0a5, ab90d2576d — interface addressable-copy skip, value-receiver Marshal/IsZero optimizations, and split marshal/unmarshal caches
  • Not yet merged in tip:
    • CL 828570 (optimize scalar marshaling, which accounted for the remaining ~26% speedup that pushed v2 past legacy in Jake Bailey's breakdown on #81315 https://github. com/golang/go/issues/81315)
    • The Oct 26 slice/struct marshaling CLs (CL 853245–853248)

That lines up directly with the data: Go tip has already recovered roughly 75%–80% of the MarshalRecords regression vs legacy, leaving only a ~9%–13% gap (down from +56%–63% in Go 1.27.3) ahead of the scalar/slice marshaling CLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment