Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
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

Merged
merged 2 commits into from
Mar 24, 2020
Merged

results: Faster JSON encoding and decoding #506

merged 2 commits into from
Mar 24, 2020

Conversation

tsenart
Copy link
Owner

@tsenart tsenart commented Mar 24, 2020

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.

Screenshot from 2020-03-24 15-07-36

Fixes #505

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)
```
@tsenart tsenart requested a review from xla as a code owner March 24, 2020 14:10
return *(*[]byte)(unsafe.Pointer(&bh))
}

func b2s(z []byte) string {

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)

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)

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)

@tsenart tsenart merged commit 3629602 into master Mar 24, 2020
@tsenart tsenart deleted the faster-json branch March 24, 2020 14:14
tsenart added a commit that referenced this pull request Mar 25, 2020
tsenart added a commit that referenced this pull request Mar 25, 2020
This commits reverts #506 because its JSON string escaping logic taken
from github.com/valyala/quicktemplate isn't complete and is incompatible
with `encoding/json`. The performance gains do not justify this short
coming (at least for Vegeta). We fix the #505 by re-generating the
easyjson encoders.
tsenart added a commit that referenced this pull request Mar 25, 2020
* Revert "results: Faster JSON encoding and decoding (#506)"

This reverts commit 3629602.

* results: Fix headers encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP headers in results produce invalid JSON
2 participants