]> Cypherpunks repositories - gostls13.git/commit
encoding/json/v2: avoid escaping jsonopts.Struct
authorJoe Tsai <joetsai@digital-static.net>
Mon, 30 Jun 2025 22:40:20 +0000 (15:40 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 30 Jun 2025 23:52:49 +0000 (16:52 -0700)
commit6bd9944c9a9fb6b1da6288358b0620218d621441
treefaadc9c53a43aa389c671b6cd6ae8ed6869b0bdc
parente46d586eddfdd2186d77a5e996bbd6415cfcf2f5
encoding/json/v2: avoid escaping jsonopts.Struct

The jsonopts.Struct.join method unfortunately escapes
the receiver because it is passed to JoinUnknownOption,
which is a dynamically implemented function.

This affects jsontext.Encoder.reset and jsontext.Decoder.reset,
which relied on a local jsonopts.Struct to temporarily store
prior options such that it would have to be heap allocated.

Adjust the signature of JoinUnknownOption to avoid pointers
so that nothing escape.

This is a regression from
https://github.com/go-json-experiment/json/pull/163

Performance:

name             old time/op    new time/op    delta
Marshal/Bool-32    72.1ns ± 2%    51.3ns ± 1%  -28.77%  (p=0.000 n=10+9)

name             old allocs/op  new allocs/op  delta
Marshal/Bool-32      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)

Updates #71845

Change-Id: Ife500d82d3d2beb13652553a4ffdf882c136f5a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/685135
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/encoding/json/internal/jsonopts/options.go
src/encoding/json/v2/options.go