1
0
mirror of https://github.com/golang/go synced 2024-10-04 23:21:20 -06:00
The Go programming language
Go to file
Peter Waldschmidt a13606e619 encoding/json: Remove extra allocation in scanner.
When the scanner receives a non-whitespace character in stateEndTop,
it creates an error message and caches it to return on the next
transition. nextValue() uses the scanner to sub-scan for a value
inside a larger JSON structure. Since stateEndTop is triggered
*after* the ending byte, whatever character immediately follows the
sub-value gets pulled into the scanner's state machine as well.
Even though it is not used and doesn't cause an error, it does
cause the state machine to allocate an error that will never be used.

The fix is to probe the state machine with whitespace after
scanEndObject or scanEndArray to see if the next character would
result in a scanEnd state transition. If so, we can return right
away without processing the next character and avoid triggering
an allocation.

benchmark                       old ns/op     new ns/op     delta
BenchmarkCodeEncoder            17022194      16611336      -2.41%
BenchmarkCodeMarshal            18443250      18090144      -1.91%
BenchmarkCodeDecoder            61502053      61010936      -0.80%
BenchmarkCodeUnmarshal          61410829      60363605      -1.71%
BenchmarkCodeUnmarshalReuse     59124836      58361772      -1.29%
BenchmarkUnmarshalString        602           603           +0.17%
BenchmarkUnmarshalFloat64       535           537           +0.37%
BenchmarkUnmarshalInt64         482           482           +0.00%
BenchmarkIssue10335             1206          799           -33.75%
BenchmarkSkipValue              17605751      18355391      +4.26%
BenchmarkEncoderEncode          612           604           -1.31%

benchmark                  old MB/s     new MB/s     speedup
BenchmarkCodeEncoder       114.00       116.82       1.02x
BenchmarkCodeMarshal       105.21       107.27       1.02x
BenchmarkCodeDecoder       31.55        31.81        1.01x
BenchmarkCodeUnmarshal     31.60        32.15        1.02x
BenchmarkSkipValue         111.63       107.07       0.96x

benchmark                  old allocs     new allocs     delta
BenchmarkIssue10335        11             4              -63.64%
BenchmarkEncoderEncode     2              2              +0.00%

benchmark                  old bytes     new bytes     delta
BenchmarkIssue10335        376           272           -27.66%
BenchmarkEncoderEncode     40            40            +0.00%

Fixes #10335

Change-Id: I3d4f2b67f7a038adfb33ba48bb6b680f528baf18
Reviewed-on: https://go-review.googlesource.com/9074
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-18 17:59:42 +00:00
api api: refresh next.txt 2015-05-14 21:31:18 +00:00
doc doc/go1.5.txt: mention sequential and RFC 6555-compliant TCP dialing 2015-06-17 06:25:05 +00:00
lib/time remove the obsolete lib/codereview. 2014-12-08 07:51:54 +00:00
misc misc/cgo/testshared: make sure rebuilds occur as expected 2015-06-17 14:55:39 +00:00
src encoding/json: Remove extra allocation in scanner. 2015-06-18 17:59:42 +00:00
test cmd/compile: run escape analysis after method wrapper generation 2015-06-17 02:36:45 +00:00
.gitattributes .gitattributes: prevent all magic line ending changes 2014-12-12 23:14:54 +00:00
.gitignore .gitignore: ignore y.output 2015-06-10 00:28:52 +00:00
AUTHORS A+C: add another email address for Emil Hessman 2014-11-12 10:01:23 -08:00
CONTRIBUTING.md doc: direct people to the mailing list 2015-01-18 21:27:07 +00:00
CONTRIBUTORS CONTRIBUTORS: add Burcu Dogan's personal mail 2015-05-06 16:06:42 +00:00
favicon.ico godoc: update favicon 2012-10-11 17:02:36 +11:00
LICENSE doc: update licensing text one more time 2012-03-27 15:09:13 +11:00
PATENTS
README.md doc: fix broken link in README 2015-02-19 05:50:57 +00:00
robots.txt godoc: serve robots.txt raw 2011-02-19 05:46:20 +11:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image

For documentation about how to install and use Go, visit https://golang.org/ or load doc/install-source.html in your web browser.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Please report issues here: https://golang.org/issue/new

Go is the work of hundreds of contributors. We appreciate your help!

To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html

Please note that we do not use pull requests.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

--

Binary Distribution Notes

If you have just untarred a binary Go distribution, you need to set the environment variable $GOROOT to the full path of the go directory (the one containing this file). You can omit the variable if you unpack it into /usr/local/go, or if you rebuild from sources by running all.bash (see doc/install-source.html). You should also add the Go binary directory $GOROOT/bin to your shell's path.

For example, if you extracted the tar file into $HOME/go, you might put the following in your .profile:

export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin

See https://golang.org/doc/install or doc/install.html for more details.