aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/bench_test.go
diff options
context:
space:
mode:
authorPascal S. de Kloe <pascal@quies.net>2016-11-16 16:35:42 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2017-03-20 23:58:56 +0000
commitdf68afd07ce67727bcc2ad8e4afaa42dbcbf58e7 (patch)
tree14047949b924ef48d05e771b251b3f5296d05bd1 /src/encoding/json/bench_test.go
parent7bb5b2d33a522d80e35f93f4c7bd6471d1d73552 (diff)
downloadgo-df68afd07ce67727bcc2ad8e4afaa42dbcbf58e7.tar.xz
encoding/json: reduce unmarshal mallocs for unmapped fields
JSON decoding performs poorly for unmapped and ignored fields. We noticed better performance when unmarshalling unused fields. The loss comes mostly from calls to scanner.error as described at #17914. benchmark old ns/op new ns/op delta BenchmarkIssue10335-8 431 408 -5.34% BenchmarkUnmapped-8 1744 1314 -24.66% benchmark old allocs new allocs delta BenchmarkIssue10335-8 4 3 -25.00% BenchmarkUnmapped-8 18 4 -77.78% benchmark old bytes new bytes delta BenchmarkIssue10335-8 320 312 -2.50% BenchmarkUnmapped-8 568 344 -39.44% Fixes #17914, improves #10335 Change-Id: I7d4258a94eb287c0fe49e7334795209b90434cd0 Reviewed-on: https://go-review.googlesource.com/33276 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/json/bench_test.go')
-rw-r--r--src/encoding/json/bench_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/encoding/json/bench_test.go b/src/encoding/json/bench_test.go
index cd7380b1ef..ec5a88a4e2 100644
--- a/src/encoding/json/bench_test.go
+++ b/src/encoding/json/bench_test.go
@@ -221,3 +221,14 @@ func BenchmarkIssue10335(b *testing.B) {
}
}
}
+
+func BenchmarkUnmapped(b *testing.B) {
+ b.ReportAllocs()
+ var s struct{}
+ j := []byte(`{"s": "hello", "y": 2, "o": {"x": 0}, "a": [1, 99, {"x": 1}]}`)
+ for n := 0; n < b.N; n++ {
+ if err := Unmarshal(j, &s); err != nil {
+ b.Fatal(err)
+ }
+ }
+}