-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
results: Faster JSON encoding and decoding #506
Conversation
This commit improves the performance of JSON encoding and decoding of `Results`. Additionally, it fixes a regression introduced in #474 that didn't produce valid JSON for HTTP headers. A test is added that validates the JSON encoding matches the one produced by the `encoding/json`. ``` name old time/op new time/op delta ResultEncodings/json-encode-16 690ns ±12% 297ns ± 0% -56.94% (p=0.000 n=9+9) ResultEncodings/json-decode-16 1.05µs ± 1% 0.03µs ± 1% -97.47% (p=0.000 n=10+8) name old alloc/op new alloc/op delta ResultEncodings/json-encode-16 804B ±87% 0B -100.00% (p=0.000 n=9+10) ResultEncodings/json-decode-16 310B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ResultEncodings/json-encode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ResultEncodings/json-decode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ```
return *(*[]byte)(unsafe.Pointer(&bh)) | ||
} | ||
|
||
func b2s(z []byte) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func b2s
is unused (from unused
)
var buf bytes.Buffer | ||
enc = tc.enc(&buf) | ||
for _, r := range results { | ||
enc.Encode(&r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of enc.Encode
is not checked (from errcheck
)
for i := 0; i < b.N; i++ { | ||
dec.Decode(&results[i%len(results)]) | ||
dec.Decode(&r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of dec.Decode
is not checked (from errcheck
)
This commit improves the performance of JSON encoding and decoding of
Results
. Additionally, it fixes a regression introduced in #474 thatdidn't produce valid JSON for HTTP headers. A test is added that
validates the JSON encoding matches the one produced by the
encoding/json
.Fixes #505