summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2024-07-07 13:30:47 -0700
committerBrad Fitzpatrick <bradfitz@tailscale.com>2024-07-07 13:34:11 -0700
commit1f845922bf3d5141226940ae766f5c1f72dc4cbd (patch)
tree1d7f33e4d7cf900d37f46171b35fb553d03d0dea
parentd2fef01206cd7a96d684f9c69ba9e767de824ab4 (diff)
downloadtailscale-bradfitz/json2.tar.xz
tailscale-bradfitz/json2.zip
types/views: add MarshalJSONV2 to Slicebradfitz/json2
It helps, but not all the way. │ before │ after │ │ B/op │ B/op vs base │ JSONMarshalView/v1_slice-8 64.00 ± 0% 64.00 ± ∞ ¹ ~ (p=1.000 n=10+1) ² JSONMarshalView/v1_view-8 136.0 ± 0% 136.0 ± ∞ ¹ ~ (p=1.000 n=10+1) ² JSONMarshalView/v2_slice-8 64.00 ± 0% 64.00 ± ∞ ¹ ~ (p=1.000 n=10+1) ² JSONMarshalView/v2_view-8 136.0 ± 0% 112.0 ± ∞ ¹ -17.65% (n=10+1) Updates tailscale/corp#14379 Updates tailscale/corp#21429 (new benchmark) Change-Id: I891dd6a4db1a995ae1be14f8c5085629bb30b8da Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
-rw-r--r--cmd/derper/depaware.txt6
-rw-r--r--cmd/stund/depaware.txt7
-rw-r--r--cmd/tailscale/depaware.txt6
-rw-r--r--cmd/tailscaled/depaware.txt7
-rw-r--r--types/views/views.go10
5 files changed, 33 insertions, 3 deletions
diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt
index cf4f36458..128b6b498 100644
--- a/cmd/derper/depaware.txt
+++ b/cmd/derper/depaware.txt
@@ -10,6 +10,12 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw
W 💣 github.com/dblohm7/wingoes from tailscale.com/util/winutil
github.com/fxamacker/cbor/v2 from tailscale.com/tka
+ github.com/go-json-experiment/json from tailscale.com/types/views
+ github.com/go-json-experiment/json/internal from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonflags from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/jsontext from github.com/go-json-experiment/json+
github.com/golang/groupcache/lru from tailscale.com/net/dnscache
L github.com/google/nftables from tailscale.com/util/linuxfw
L 💣 github.com/google/nftables/alignedbuff from github.com/google/nftables/xt
diff --git a/cmd/stund/depaware.txt b/cmd/stund/depaware.txt
index d1528c7ac..a35bbe84f 100644
--- a/cmd/stund/depaware.txt
+++ b/cmd/stund/depaware.txt
@@ -2,6 +2,12 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar
github.com/beorn7/perks/quantile from github.com/prometheus/client_golang/prometheus
💣 github.com/cespare/xxhash/v2 from github.com/prometheus/client_golang/prometheus
+ github.com/go-json-experiment/json from tailscale.com/types/views
+ github.com/go-json-experiment/json/internal from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonflags from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/jsontext from github.com/go-json-experiment/json+
github.com/google/uuid from tailscale.com/util/fastuuid
💣 github.com/prometheus/client_golang/prometheus from tailscale.com/tsweb/promvarz
github.com/prometheus/client_golang/prometheus/internal from github.com/prometheus/client_golang/prometheus
@@ -128,6 +134,7 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar
embed from crypto/internal/nistec+
encoding from encoding/json+
encoding/asn1 from crypto/x509+
+ encoding/base32 from github.com/go-json-experiment/json
encoding/base64 from encoding/json+
encoding/binary from compress/gzip+
encoding/hex from crypto/x509+
diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt
index 7b3d09af8..70aff43da 100644
--- a/cmd/tailscale/depaware.txt
+++ b/cmd/tailscale/depaware.txt
@@ -9,6 +9,12 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
W 💣 github.com/dblohm7/wingoes from github.com/dblohm7/wingoes/pe+
W 💣 github.com/dblohm7/wingoes/pe from tailscale.com/util/winutil/authenticode
github.com/fxamacker/cbor/v2 from tailscale.com/tka
+ github.com/go-json-experiment/json from tailscale.com/types/views
+ github.com/go-json-experiment/json/internal from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonflags from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json+
+ github.com/go-json-experiment/json/jsontext from github.com/go-json-experiment/json+
github.com/golang/groupcache/lru from tailscale.com/net/dnscache
L github.com/google/nftables from tailscale.com/util/linuxfw
L 💣 github.com/google/nftables/alignedbuff from github.com/google/nftables/xt
diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt
index 6a8f53494..b5f3be1de 100644
--- a/cmd/tailscaled/depaware.txt
+++ b/cmd/tailscaled/depaware.txt
@@ -90,11 +90,12 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
💣 github.com/djherbis/times from tailscale.com/drive/driveimpl
github.com/fxamacker/cbor/v2 from tailscale.com/tka
github.com/gaissmai/bart from tailscale.com/net/tstun+
+ github.com/go-json-experiment/json from tailscale.com/types/views
github.com/go-json-experiment/json/internal from github.com/go-json-experiment/json/internal/jsonflags+
github.com/go-json-experiment/json/internal/jsonflags from github.com/go-json-experiment/json/internal/jsonopts+
- github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json/jsontext
- github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json/jsontext
- github.com/go-json-experiment/json/jsontext from tailscale.com/logtail
+ github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json/jsontext+
+ github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json/jsontext+
+ github.com/go-json-experiment/json/jsontext from tailscale.com/logtail+
W 💣 github.com/go-ole/go-ole from github.com/go-ole/go-ole/oleutil+
W 💣 github.com/go-ole/go-ole/oleutil from tailscale.com/wgengine/winnet
L 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns+
diff --git a/types/views/views.go b/types/views/views.go
index 42758966f..fa0e45adb 100644
--- a/types/views/views.go
+++ b/types/views/views.go
@@ -13,6 +13,9 @@ import (
"maps"
"slices"
+ jsonexp "github.com/go-json-experiment/json"
+ jsontext "github.com/go-json-experiment/json/jsontext"
+
"go4.org/mem"
)
@@ -225,6 +228,13 @@ func (v Slice[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(v.ж)
}
+var _ jsonexp.MarshalerV2 = Slice[string]{nil}
+
+// MarshalJSON implements github.com/go-json-experiment/json.MarshalerV2.
+func (v Slice[T]) MarshalJSONV2(e *jsontext.Encoder, opts jsonexp.Options) error {
+ return jsonexp.MarshalEncode(e, v.ж, opts)
+}
+
// UnmarshalJSON implements json.Unmarshaler.
func (v *Slice[T]) UnmarshalJSON(b []byte) error {
return unmarshalSliceFromJSON(b, &v.ж)