commit | 1e09691415f368f1b5ce2989cc8d6aab01cb1fd3 | [log] [tgz] |
---|---|---|
author | Herbie Ong <herbie@google.com> | Tue Apr 16 00:14:03 2019 -0700 |
committer | Herbie Ong <herbie@google.com> | Wed Apr 17 00:26:13 2019 +0000 |
tree | 2a67360dee3975f337fa7e3a7c1053bca0c2db00 | |
parent | 00e50dc9c1830e440bb7d0d2f4a4da39c67d0c26 [diff] |
internal/encoding/{json,text}: improve string parsing Previous calls to indexNeedEscape with a type conversion from []byte to string incurs allocation. Make 2 different calls instead, one for string and one for bytes. Type converting string to []byte does not incur extra allocation, however, the benchmark results still show it to be slower by ~3% for textpb and 6+% for jsonpb, hence decided to go with 2 separate calls instead. Results over current head: name old time/op new time/op delta TextEncode-4 18.1ms ± 2% 18.3ms ± 2% ~ (p=0.065 n=10+9) TextDecode-4 233ms ± 3% 102ms ± 1% -56.34% (p=0.000 n=9+10) JSONEncode-4 10.4ms ± 2% 10.5ms ± 0% +0.56% (p=0.019 n=9+9) JSONDecode-4 870ms ± 2% 354ms ± 4% -59.33% (p=0.000 n=9+10) name old alloc/op new alloc/op delta TextEncode-4 28.9MB ± 0% 28.9MB ± 0% +0.00% (p=0.000 n=10+9) TextDecode-4 1.16GB ± 0% 0.03GB ± 0% -97.44% (p=0.000 n=9+10) JSONEncode-4 3.94MB ± 0% 3.94MB ± 0% +0.00% (p=0.000 n=10+10) JSONDecode-4 3.35GB ± 0% 0.01GB ± 0% -99.83% (p=0.000 n=10+10) name old allocs/op new allocs/op delta TextEncode-4 73.5k ± 0% 73.5k ± 0% ~ (all equal) TextDecode-4 278k ± 0% 255k ± 0% -8.26% (p=0.000 n=9+10) JSONEncode-4 63.8k ± 0% 63.8k ± 0% ~ (all equal) JSONDecode-4 247k ± 0% 210k ± 0% -14.92% (p=0.000 n=10+10) Change-Id: Ibc64e9a7827ec1fffa213eb79f60497950203700 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/172239 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
WARNING: This repository is in active development. There are no guarantees about API stability. Breaking changes will occur until a stable release is made and announced.
This repository is for the development of the next major Go implementation of protocol buffers. This library makes breaking API changes relative to the existing Go protobuf library. Of particular note, this API aims to make protobuf reflection a first-class feature of the API and implements the protobuf ecosystem in terms of reflection.
List of relevant design documents:
We appreciate community contributions. See CONTRIBUTING.md.
Issues regarding the new API can be filed at github.com/golang/protobuf. Please use a APIv2:
prefix in the title to make it clear that the issue is regarding the new API work.