Commit Graph

5 Commits

Author SHA1 Message Date
Olivier Poitrey 72d41dedeb Add []byte fields support
Add efficient []byte field support with no string conversion.
2017-07-01 12:48:32 -07:00
Olivier Poitrey 447d0fc7f5 Optimize JSON encoding even further
Last optimization was for JSON string with no character to encode. This
version focuses on strings with some chars to encode, trying to apply
the same trick for substrings that do not need encoding.

benchmark                old ns/op     new ns/op    delta
.../NoEncoding-8         60.2          51.3         -14.78%
.../EncodingFirst-8      140           116          -17.14%
.../EncodingMiddle-8     112           86.4         -22.86%
.../EncodingLast-8       62.8          61.1         -2.71%
.../MultiBytesFirst-8    164           129          -21.34%
.../MultiBytesMiddle-8   133           96.9         -27.14%
.../MultiBytesLast-8     81.9          73.5         -10.26%
2017-06-25 15:17:49 -07:00
Olivier Poitrey 9c5f03507d Add some json encoder benchmarks 2017-06-25 15:17:49 -07:00
Josh Baker f8aa7a1962 Optimistically expect simple strings for json (#6)
Performance update to appendJSONString so that it now checks if
the input is a simple string that contains no json delimiters, control
characters, or unicode. If simple then the operation is only three
appends. [double-quote, string, double-quote].

If a non-simple character is encountered then all of the previous
characters are appended and the operation falls back to the original
method for the remaining characters.

Before:

  BenchmarkLogEmpty-8	    100000000	        17.1 ns/op
  BenchmarkDisabled-8	    500000000	         4.12 ns/op
  BenchmarkInfo-8		    20000000	       101 ns/op
  BenchmarkContextFields-8    20000000	       105 ns/op
  BenchmarkLogFields-8	     5000000	       281 ns/op

After:

  BenchmarkLogEmpty-8	    100000000	        16.7 ns/op
  BenchmarkDisabled-8	    500000000	         3.79 ns/op
  BenchmarkInfo-8		    30000000	        44.8 ns/op
  BenchmarkContextFields-8    30000000	        67.5 ns/op
  BenchmarkLogFields-8	    10000000	       197 ns/op
2017-06-23 20:28:33 -07:00
Olivier Poitrey fa2d76dd80 Add some test 2017-05-19 21:57:46 -07:00