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

Issue 5411052: code review 5411052: json: use strconv.Append variants to avoid allocations ... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 3 months ago by bradfitz
Modified:
13 years, 3 months ago
Reviewers:
CC:
golang-dev, dsymonds, rsc, r, gri
Visibility:
Public.

Description

json: use strconv.Append variants to avoid allocations in encoding Before/after, best of 3: json.BenchmarkCodeEncoder 10 183495300 ns/op 10.58 MB/s -> json.BenchmarkCodeEncoder 10 133025100 ns/op 14.59 MB/s But don't get too excited about this. These benchmarks, while stable at any point of time, fluctuate wildly with any line of code added or removed anywhere in the path due to stack splitting issues. It's currently much faster, though, and this is the API that doesn't allocate so should always be faster in theory.

Patch Set 1 #

Patch Set 2 : diff -r e2a939a05cd7 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r e2a939a05cd7 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 4a5b249ef23d https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 4a5b249ef23d https://go.googlecode.com/hg/ #

Total comments: 9

Patch Set 6 : diff -r 4a5b249ef23d https://go.googlecode.com/hg/ #

Total comments: 10

Patch Set 7 : diff -r c8f7a5a37d09 https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 56842d9b23d2 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 9 : diff -r 56842d9b23d2 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+19 lines, -6 lines) Patch
M src/pkg/encoding/json/encode.go View 1 2 3 4 5 6 2 chunks +19 lines, -6 lines 0 comments Download

Messages

Total messages: 27
bradfitz
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 3 months ago (2011-11-18 12:27:20 UTC) #1
bradfitz
Consider this a feeler CL. I didn't write docs but you can imagine what they'd ...
13 years, 3 months ago (2011-11-18 12:29:35 UTC) #2
dsymonds
You say there are fewer allocations. Is there a benchmark to demonstrate that?
13 years, 3 months ago (2011-11-18 12:51:55 UTC) #3
bradfitz
There is not. But I just added some printlns to BenchmarkEncoder before & after the ...
13 years, 3 months ago (2011-11-18 13:08:13 UTC) #4
rsc
Thanks for trying this. It is not as much faster as I had expected. Can ...
13 years, 3 months ago (2011-11-18 13:36:38 UTC) #5
bradfitz
On Fri, Nov 18, 2011 at 5:36 AM, Russ Cox <rsc@golang.org> wrote: > Thanks for ...
13 years, 3 months ago (2011-11-18 14:34:36 UTC) #6
bradfitz
Hello golang-dev@googlegroups.com, dsymonds@golang.org, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2011-11-21 16:10:33 UTC) #7
bradfitz
Russ, Thoughts on this one? I'm not sure how big of a speed-up you were ...
13 years, 3 months ago (2011-11-21 16:14:17 UTC) #8
rsc
Try with -run=xxx to avoid running the tests? The profile says that reflect.Value.MapKeys is getting ...
13 years, 3 months ago (2011-11-21 16:48:29 UTC) #9
bradfitz
I thought I already ran with -run=xxx (I normally do), but I guess not. Attached. ...
13 years, 3 months ago (2011-11-21 18:04:43 UTC) #10
bradfitz
Faster with special-casing division by 10: before: json.BenchmarkCodeEncoder 100 127088880 ns/op 15.27 MB/s then: json.BenchmarkCodeEncoder ...
13 years, 3 months ago (2011-11-21 18:16:41 UTC) #11
bradfitz
Hello golang-dev@googlegroups.com, dsymonds@golang.org, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2011-11-21 18:17:56 UTC) #12
r
http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go File src/pkg/strconv/itoa.go (right): http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go#newcode9 src/pkg/strconv/itoa.go:9: if base < 2 || 36 < base { ...
13 years, 3 months ago (2011-11-22 22:48:13 UTC) #13
bradfitz
http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go File src/pkg/strconv/itoa.go (right): http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go#newcode9 src/pkg/strconv/itoa.go:9: if base < 2 || 36 < base { ...
13 years, 3 months ago (2011-11-23 03:29:52 UTC) #14
bradfitz
http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go File src/pkg/strconv/itoa.go (right): http://codereview.appspot.com/5411052/diff/1002/src/pkg/strconv/itoa.go#newcode9 src/pkg/strconv/itoa.go:9: if base < 2 || 36 < base { ...
13 years, 3 months ago (2011-11-23 03:30:56 UTC) #15
bradfitz
Hello golang-dev@googlegroups.com, dsymonds@golang.org, rsc@golang.org, r@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2011-11-23 03:33:20 UTC) #16
r
LGTM but wait for rsc http://codereview.appspot.com/5411052/diff/13002/src/pkg/strconv/itoa.go File src/pkg/strconv/itoa.go (right): http://codereview.appspot.com/5411052/diff/13002/src/pkg/strconv/itoa.go#newcode32 src/pkg/strconv/itoa.go:32: // returning a string. ...
13 years, 3 months ago (2011-11-23 17:38:08 UTC) #17
r
http://codereview.appspot.com/5411052/diff/13002/src/pkg/strconv/itoa.go File src/pkg/strconv/itoa.go (right): http://codereview.appspot.com/5411052/diff/13002/src/pkg/strconv/itoa.go#newcode87 src/pkg/strconv/itoa.go:87: // returning a string. and returns the resulting slice.
13 years, 3 months ago (2011-11-23 17:38:48 UTC) #18
gri
I think this can be streamlined quite a bit. Come to think of it, I ...
13 years, 3 months ago (2011-11-23 18:17:36 UTC) #19
bradfitz
Hello golang-dev@googlegroups.com, dsymonds@golang.org, rsc@golang.org, r@golang.org, gri@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2011-12-06 21:56:33 UTC) #20
bradfitz
I've now dropped all my AppendFloat, etc changes from this CL. I won't submit until ...
13 years, 3 months ago (2011-12-06 21:57:59 UTC) #21
gri
Thanks. My code changes are very similar, but with some additional simplifications thrown in. - ...
13 years, 3 months ago (2011-12-07 00:08:21 UTC) #22
bradfitz
Hello golang-dev@googlegroups.com, dsymonds@golang.org, rsc@golang.org, r@golang.org, gri@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2011-12-15 19:16:44 UTC) #23
rsc
LGTM
13 years, 3 months ago (2011-12-15 19:20:27 UTC) #24
gri
http://codereview.appspot.com/5411052/diff/21001/src/pkg/encoding/json/encode.go File src/pkg/encoding/json/encode.go (right): http://codereview.appspot.com/5411052/diff/21001/src/pkg/encoding/json/encode.go#newcode281 src/pkg/encoding/json/encode.go:281: writeString(e, string(b)) I think it should be faster to ...
13 years, 3 months ago (2011-12-15 19:20:54 UTC) #25
bradfitz
*** Submitted as http://code.google.com/p/go/source/detail?r=0e5409a34221 *** json: use strconv.Append variants to avoid allocations in encoding Before/after, ...
13 years, 3 months ago (2011-12-15 19:21:26 UTC) #26
bradfitz
13 years, 3 months ago (2011-12-15 19:23:23 UTC) #27
On Thu, Dec 15, 2011 at 11:20 AM, <gri@golang.org> wrote:

>
> http://codereview.appspot.com/**5411052/diff/21001/src/pkg/**
>
encoding/json/encode.go<http://codereview.appspot.com/5411052/diff/21001/src/pkg/encoding/json/encode.go>
> File src/pkg/encoding/json/encode.**go (right):
>
> http://codereview.appspot.com/**5411052/diff/21001/src/pkg/**
>
encoding/json/encode.go#**newcode281<http://codereview.appspot.com/5411052/diff/21001/src/pkg/encoding/json/encode.go#newcode281>
> src/pkg/encoding/json/encode.**go:281: writeString(e, string(b))
> I think it should be faster to use
>
> writeString(w, strconv.FormatInt(...))
>

Whoops, already submitted.  In any case, that quoted path is almost never
hit.  Only when sending int64s to JSON APIs like Google's, where int64s
aren't safe by themselves.  I'd prefer less code to more performance in a
fringe case.
Sign in to reply to this message.

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