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

Issue 12243043: code review 12243043: encoding/json: Speed up decoding by 50% (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 6 months ago by Hierro
Modified:
12 years, 6 months ago
Visibility:
Public.

Description

encoding/json: Speed up decoding by 50% * Avoid recalculating len(data) while decoding. * Avoid excessive byte to int castings. * Avoid creating temporary slices in nextValue(), returning an offset suffices. * Cache key <=> field lookups. They use strings.EqualFold, which is pretty slow. * Avoid converting keys to strings when possible. Benchmarks: benchmark old ns/op new ns/op delta BenchmarkCodeUnmarshal 146540233 98708913 -32.64% BenchmarkCodeUnmarshalMethod 148930131 98619151 -33.78% BenchmarkCodeUnmarshalReuse 143297363 90978323 -36.51% benchmark old MB/s new MB/s speedup BenchmarkCodeUnmarshal 13.24 19.66 1.48x BenchmarkCodeUnmarshalMethod 13.03 19.68 1.51x BenchmarkCodeUnmarshalReuse 13.54 21.33 1.58x benchmark old allocs new allocs delta BenchmarkCodeUnmarshal 195377 105750 -45.87% BenchmarkCodeUnmarshalMethod 195376 105748 -45.87% BenchmarkCodeUnmarshalReuse 180345 89892 -50.16% benchmark old bytes new bytes delta BenchmarkCodeUnmarshal 4274092 3457209 -19.11% BenchmarkCodeUnmarshalMethod 4273988 3456867 -19.12% BenchmarkCodeUnmarshalReuse 2937147 2047975 -30.27%

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

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

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+161 lines, -99 lines) Patch
M src/pkg/encoding/json/bench_test.go View 3 chunks +36 lines, -0 lines 0 comments Download
M src/pkg/encoding/json/decode.go View 12 chunks +63 lines, -42 lines 3 comments Download
M src/pkg/encoding/json/decode_test.go View 1 chunk +1 line, -1 line 1 comment Download
M src/pkg/encoding/json/indent.go View 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/encoding/json/scanner.go View 37 chunks +50 lines, -50 lines 1 comment Download
M src/pkg/encoding/json/scanner_test.go View 2 chunks +7 lines, -2 lines 0 comments Download
M src/pkg/encoding/json/stream.go View 2 chunks +2 lines, -2 lines 0 comments Download

Messages

Total messages: 25
Hierro
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
12 years, 6 months ago (2013-08-01 10:28:01 UTC) #1
Hierro
Here are some benchmarks before and after applying this patch set: Before: BenchmarkCodeUnmarshal 10 156293404 ...
12 years, 6 months ago (2013-08-01 10:31:27 UTC) #2
dsymonds
Please use misc/benchcmp to compare benchmark output, and include it in the CL description.
12 years, 6 months ago (2013-08-01 10:36:18 UTC) #3
remyoudompheng
Is it possible for you to post CPU profiles? I would like to know if ...
12 years, 6 months ago (2013-08-01 10:50:52 UTC) #4
Hierro
On 2013/08/01 10:36:18, dsymonds wrote: > Please use misc/benchcmp to compare benchmark output, and include ...
12 years, 6 months ago (2013-08-01 10:52:46 UTC) #5
Hierro
On 2013/08/01 10:50:52, remyoudompheng wrote: > Is it possible for you to post CPU profiles? ...
12 years, 6 months ago (2013-08-01 10:57:29 UTC) #6
rog
I'd like to see the incremental effect of each change included in this CL, rather ...
12 years, 6 months ago (2013-08-01 13:45:19 UTC) #7
Hierro
On 2013/08/01 13:45:19, rog wrote: > I'd like to see the incremental effect of each ...
12 years, 6 months ago (2013-08-01 14:29:28 UTC) #8
r
Do not use the unsafe package just to gain performance in the standard libraries. -rob
12 years, 6 months ago (2013-08-01 14:45:42 UTC) #9
rsc
Brad also has a pending CL to make json faster. I think we all agree ...
12 years, 6 months ago (2013-08-01 14:47:28 UTC) #10
Hierro
On 2013/08/01 14:47:28, rsc wrote: > Brad also has a pending CL to make json ...
12 years, 6 months ago (2013-08-01 15:23:01 UTC) #11
rsc
Everything I wrote still applies. I didn't mention encoding vs decoding.
12 years, 6 months ago (2013-08-01 15:24:06 UTC) #12
Hierro
On 2013/08/01 14:45:42, r wrote: > Do not use the unsafe package just to gain ...
12 years, 6 months ago (2013-08-01 15:27:34 UTC) #13
bradfitz
Any ETA on that thinking? Or guidelines for what class of performance improvements (if any) ...
12 years, 6 months ago (2013-08-01 17:29:54 UTC) #14
r
Because I don't want any more of this in the library. Because I'd rather see ...
12 years, 6 months ago (2013-08-01 21:43:30 UTC) #15
Hierro
On 2013/08/01 21:43:30, r wrote: > Because I don't want any more of this in ...
12 years, 6 months ago (2013-08-02 11:48:09 UTC) #16
Hierro
On 2013/08/01 15:24:06, rsc wrote: > Everything I wrote still applies. I didn't mention encoding ...
12 years, 6 months ago (2013-08-02 11:49:01 UTC) #17
r
It was a mistake to export reflect.StructHeader. It's another mistake to build on that mistake. ...
12 years, 6 months ago (2013-08-02 12:56:18 UTC) #18
rsc
> In the meantime, I take full responsibility for that ugly line of code. You ...
12 years, 6 months ago (2013-08-06 16:39:21 UTC) #19
rsc
I don't understand your first bullet in the CL description "avoid recalculating len(data)". I can't ...
12 years, 6 months ago (2013-08-06 17:05:10 UTC) #20
Hierro
On 2013/08/06 17:05:10, rsc wrote: > I don't understand your first bullet in the CL ...
12 years, 6 months ago (2013-08-06 21:58:32 UTC) #21
Hierro
*** Abandoned ***
12 years, 6 months ago (2013-08-06 21:59:32 UTC) #22
bradfitz
On Tue, Aug 6, 2013 at 2:58 PM, <alberto.garcia.hierro@gmail.com> wrote: > I'll drop this CL ...
12 years, 6 months ago (2013-08-07 01:45:53 UTC) #23
Hierro
On 2013/08/07 01:45:53, bradfitz wrote: > I don't know what your internal review process is ...
12 years, 6 months ago (2013-08-07 12:12:15 UTC) #24
iant
12 years, 6 months ago (2013-08-07 14:41:35 UTC) #25
On Wed, Aug 7, 2013 at 5:12 AM,  <alberto.garcia.hierro@gmail.com> wrote:
>
> I try to submit all our changes to the standard packages and the
> compilers as CLs, but due to your development process it takes a lot of
> time. e.g. we have had support for calling C function pointers for
> almost 2 months now. I submitted a CL for adding support for C function
> pointer variables (since the code for calling them wasn't tested enough
> at the time) 2 months and a week ago and it's still sitting there. If it
> gets accepted, then I have to dig up our commit (or commits) which added
> support for calling C function pointers, its tests, etc… apply it to a
> clean Go checkout, check any open Go issues that it might fix and submit
> it as a CL. Again, this takes a lot of time and some times the reviews
> are not very friendly (e.g. some reviews feel like "this is our language
> and we get to decide, so shut up now. Oh, and you're stupid for
> suggesting that").
>
> Lately, I've opted for adding most of the code we develop to our
> internal web framework (which we hope to release some day), rather than
> submitting it for inclusion in Go. e.g. we have full i18n support, which
> extracts the strings from Go code, generates standard .po files and them
> compiles those .po files to .go files rather than .mo. This way,
> packages with translations are still "go get-able". As you may know, po
> translation files include a formula for choosing a plural form for a
> given number. I initially wrote a simple register based VM to interpret
> those formulas, but it felt kind of slow (it took ~2x time than go
> compiled code), so I wrote a JIT for it which even outperforms the gc
> compiler (for these formulas, which are quite simple). If I were to
> submit this for inclusion in Go, I'm pretty sure the JIT wouldn't get
> accepted and I would probably have to argue for weeks or months about
> every choice I made during the design of the i18n support. It's really
> not worth it.
>
> What I'm trying to say is that I feel that the process of contributing
> code to Go as an outsider to Google is way more difficult than it should
> be and, in the long term, this hurts the Go ecosystem.

I'm sorry you find the process frustrating.  You're not alone in that.
We do tend to move slowly and incrementally in the standard
repository, because we know that decisions made there last a long
time, and require maintenance.  Significant changes to the standard
repository are discussed on golang-dev before they become a CL, and
many of them have a design document.

Your function pointer CL did get a reply 5 days ago.  I agree it sat
there too long.  That long-delayed comment was reasonable: significant
new functionality like your CL does require a test.  I also just added
a few more comments to the CL and I hope you will push it forward.

Your i18n code sounds useful for many people.  It wouldn't go into the
standard repository in any case--the i18n support is currently in the
separate go.text repository (http://code.google.com/p/go.text).  If
you would like to send a design doc to golang-dev, I think it would be
well received, but, you're right, people would discuss it for a
while.  I hope you will at least consider releasing it yourself on
github or wherever.

I want to be clear that this is not an inside/outside Google thing;
the same issues arise for people inside Google.  There are ways to get
changes in: discuss the design first, send small incremental CLs,
build a track record of success.  But, yes, it's slow and often
frustrating.  It's not a free-for-all for anybody.

I don't have any real comments on this encoding/json CL except to
observe that although App Engine is understandably not important for
you, it is important for many people.  We simply can't change a
fundamental package like encoding/json such that it can not be used on
App Engine.  That's a non-starter.

I hope you can continue to use Go happily.

Ian
Sign in to reply to this message.

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