Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(408)

Issue 100070043: code review 100070043: encoding/json: make MarshalIndent faster

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 1 month ago by ruiu
Modified:
11 years, 11 months ago
Reviewers:
gobot, golang-codereviews, dave, rsc, r, bradfitz
CC:
golang-codereviews
Visibility:
Public.

Description

encoding/json: make MarshalIndent faster MarshalIndent was more than four times slower than Marshal. "newline" function was notably slow because of repeating calls to WriteString. This patch makes it more efficient. benchmark old ns/op new ns/op delta BenchmarkCodeMarshalIndent 99141396 68867402 -30.54% BenchmarkIndent 71616746 40213030 -43.85% benchmark old MB/s new MB/s speedup BenchmarkCodeMarshalIndent 19.57 28.18 1.44x BenchmarkIndent 27.10 48.25 1.78x benchmark old allocs new allocs delta BenchmarkIndent 8 8 0.00%

Patch Set 1 #

Patch Set 2 : diff -r 2e591e82a8c8 https://code.google.com/p/go #

Patch Set 3 : diff -r 2e591e82a8c8 https://code.google.com/p/go #

Patch Set 4 : diff -r 6146799f32ed https://code.google.com/p/go #

Patch Set 5 : diff -r 6146799f32ed https://code.google.com/p/go #

Total comments: 2

Patch Set 6 : diff -r 6146799f32ed https://code.google.com/p/go #

Patch Set 7 : diff -r 0e00c0f7e28e https://code.google.com/p/go #

Patch Set 8 : diff -r 0e00c0f7e28e https://code.google.com/p/go #

Total comments: 4

Patch Set 9 : diff -r 2dc2bf98e6e3 https://code.google.com/p/go #

Total comments: 1

Patch Set 10 : diff -r 2dc2bf98e6e3 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+76 lines, -12 lines) Patch
M src/pkg/encoding/json/bench_test.go View 1 2 3 4 5 6 7 8 9 1 chunk +36 lines, -0 lines 0 comments Download
M src/pkg/encoding/json/indent.go View 1 2 3 4 5 6 7 8 6 chunks +40 lines, -12 lines 0 comments Download

Messages

Total messages: 20
ruiu
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
12 years ago (2014-06-11 03:00:32 UTC) #1
dave_cheney.net
https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go File src/pkg/encoding/json/indent.go (right): https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go#newcode81 src/pkg/encoding/json/indent.go:81: w.dst.WriteString(w.prefix) is there a reason that the '\n' cannot ...
12 years ago (2014-06-11 03:05:20 UTC) #2
ruiu
https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go File src/pkg/encoding/json/indent.go (right): https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go#newcode81 src/pkg/encoding/json/indent.go:81: w.dst.WriteString(w.prefix) We could, and it sounds like a good ...
12 years ago (2014-06-11 03:10:35 UTC) #3
dave_cheney.net
On 2014/06/11 03:10:35, ruiu wrote: > https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go > File src/pkg/encoding/json/indent.go (right): > > https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go#newcode81 > ...
12 years ago (2014-06-11 08:59:37 UTC) #4
dave_cheney.net
On 2014/06/11 08:59:37, dfc wrote: > On 2014/06/11 03:10:35, ruiu wrote: > > > https://codereview.appspot.com/100070043/diff/70001/src/pkg/encoding/json/indent.go ...
12 years ago (2014-06-11 09:14:53 UTC) #5
ruiu
How about managing newlineWriter using sync.Pool to avoid allocation? It feels cleaner to me than ...
12 years ago (2014-06-11 20:19:00 UTC) #6
dave_cheney.net
My CL was just a suggestion, I didn't want to steal your thunder. Give sync.Pool ...
12 years ago (2014-06-11 20:21:29 UTC) #7
ruiu
Yeah I didn't mean it, but just wanted to get your input about sync.Pool. :) ...
12 years ago (2014-06-11 20:26:18 UTC) #8
ruiu
Hello golang-codereviews@googlegroups.com, dave@cheney.net (cc: golang-codereviews@googlegroups.com), Please take another look.
12 years ago (2014-06-12 01:50:06 UTC) #9
ruiu
Ping.
12 years ago (2014-06-16 23:01:10 UTC) #10
bradfitz
https://codereview.appspot.com/100070043/diff/130001/src/pkg/encoding/json/indent.go File src/pkg/encoding/json/indent.go (right): https://codereview.appspot.com/100070043/diff/130001/src/pkg/encoding/json/indent.go#newcode72 src/pkg/encoding/json/indent.go:72: var nwPool sync.Pool I'd add the New func here, ...
12 years ago (2014-06-16 23:37:41 UTC) #11
ruiu
https://codereview.appspot.com/100070043/diff/130001/src/pkg/encoding/json/indent.go File src/pkg/encoding/json/indent.go (right): https://codereview.appspot.com/100070043/diff/130001/src/pkg/encoding/json/indent.go#newcode72 src/pkg/encoding/json/indent.go:72: var nwPool sync.Pool Done with newlines after { and ...
12 years ago (2014-06-16 23:47:47 UTC) #12
bradfitz
LGTM code-wise but give rsc a day or two to look first
12 years ago (2014-06-16 23:57:49 UTC) #13
bradfitz
https://codereview.appspot.com/100070043/diff/150001/src/pkg/encoding/json/bench_test.go File src/pkg/encoding/json/bench_test.go (right): https://codereview.appspot.com/100070043/diff/150001/src/pkg/encoding/json/bench_test.go#newcode114 src/pkg/encoding/json/bench_test.go:114: if _, err := MarshalIndent(&codeStruct, "", " "); err ...
12 years ago (2014-06-16 23:59:04 UTC) #14
ruiu
Makes sense. Added BenchmarkIndent. The result of the benchmark is this (also pasted to the ...
12 years ago (2014-06-17 00:57:17 UTC) #15
dave_cheney.net
On 17/06/2014, at 9:37, bradfitz@golang.org wrote: > > https://codereview.appspot.com/100070043/diff/130001/src/pkg/encoding/json/indent.go > File src/pkg/encoding/json/indent.go (right): > > ...
12 years ago (2014-06-17 03:21:38 UTC) #16
ruiu
On 2014/06/17 03:21:38, dfc wrote: > > On 17/06/2014, at 9:37, mailto:bradfitz@golang.org wrote: > > ...
12 years ago (2014-06-17 15:42:15 UTC) #17
dave_cheney.net
Sure thing, go for it. On Wed, Jun 18, 2014 at 1:42 AM, <ruiu@google.com> wrote: ...
12 years ago (2014-06-17 23:47:19 UTC) #18
r
NOT LGTM Sync.Pool is not meant to live in every package.
12 years ago (2014-06-22 05:52:42 UTC) #19
gobot
11 years, 11 months ago (2014-07-16 10:56:51 UTC) #20
R=close (assigned by dave@cheney.net)
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b