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

Add pool for bitwriters #185

Merged
merged 1 commit into from
Nov 22, 2019
Merged

Add pool for bitwriters #185

merged 1 commit into from
Nov 22, 2019

Conversation

klauspost
Copy link
Owner

@klauspost klauspost commented Nov 22, 2019

Remove stateless allocations with a sync.Pool.
Remove unneeded zeroing.

λ benchstat old.txt new.txt
name                  old time/op    new time/op    delta
EncodeDigitsSL1e4-12     128µs ± 1%     130µs ± 5%     ~     (p=0.690 n=5+5)
EncodeDigitsSL1e5-12     847µs ± 0%     853µs ± 1%   +0.71%  (p=0.016 n=5+5)
EncodeDigitsSL1e6-12    7.77ms ± 1%    7.76ms ± 1%     ~     (p=0.841 n=5+5)
EncodeTwainSL1e4-12      140µs ± 0%     139µs ± 2%     ~     (p=0.151 n=5+5)
EncodeTwainSL1e5-12      873µs ± 0%     865µs ± 0%   -0.94%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12     7.95ms ± 0%    7.91ms ± 0%   -0.54%  (p=0.032 n=5+5)

name                  old speed      new speed      delta
EncodeDigitsSL1e4-12  78.2MB/s ± 1%  77.1MB/s ± 5%     ~     (p=0.690 n=5+5)
EncodeDigitsSL1e5-12   118MB/s ± 0%   117MB/s ± 1%   -0.71%  (p=0.016 n=5+5)
EncodeDigitsSL1e6-12   129MB/s ± 1%   129MB/s ± 1%     ~     (p=0.841 n=5+5)
EncodeTwainSL1e4-12   71.3MB/s ± 0%  72.2MB/s ± 2%     ~     (p=0.151 n=5+5)
EncodeTwainSL1e5-12    115MB/s ± 0%   116MB/s ± 0%   +0.95%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12    126MB/s ± 0%   126MB/s ± 0%   +0.54%  (p=0.032 n=5+5)

name                  old alloc/op   new alloc/op   delta
EncodeDigitsSL1e4-12    12.0kB ± 0%     0.0kB ± 0%  -99.72%  (p=0.008 n=5+5)
EncodeDigitsSL1e5-12    12.0kB ± 0%     0.0kB ± 0%  -99.68%  (p=0.008 n=5+5)
EncodeDigitsSL1e6-12    12.0kB ± 0%     0.1kB ± 0%  -99.23%  (p=0.008 n=5+5)
EncodeTwainSL1e4-12     12.0kB ± 0%     0.0kB ± 0%  -99.72%  (p=0.008 n=5+5)
EncodeTwainSL1e5-12     12.0kB ± 0%     0.0kB ± 0%  -99.68%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12     12.0kB ± 0%     0.1kB ± 0%  -99.22%  (p=0.008 n=5+5)

name                  old allocs/op  new allocs/op  delta
EncodeDigitsSL1e4-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeDigitsSL1e5-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeDigitsSL1e6-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e4-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e5-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)

The benchmark does one write/op, so the real-world impact is bigger than indicated by what is indicated above.

Remove stateless allocations with a sync.Pool.
Remove unneeded zeroing.

```
λ benchstat old.txt new.txt
name                  old time/op    new time/op    delta
EncodeDigitsSL1e4-12     128µs ± 1%     130µs ± 5%     ~     (p=0.690 n=5+5)
EncodeDigitsSL1e5-12     847µs ± 0%     853µs ± 1%   +0.71%  (p=0.016 n=5+5)
EncodeDigitsSL1e6-12    7.77ms ± 1%    7.76ms ± 1%     ~     (p=0.841 n=5+5)
EncodeTwainSL1e4-12      140µs ± 0%     139µs ± 2%     ~     (p=0.151 n=5+5)
EncodeTwainSL1e5-12      873µs ± 0%     865µs ± 0%   -0.94%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12     7.95ms ± 0%    7.91ms ± 0%   -0.54%  (p=0.032 n=5+5)

name                  old speed      new speed      delta
EncodeDigitsSL1e4-12  78.2MB/s ± 1%  77.1MB/s ± 5%     ~     (p=0.690 n=5+5)
EncodeDigitsSL1e5-12   118MB/s ± 0%   117MB/s ± 1%   -0.71%  (p=0.016 n=5+5)
EncodeDigitsSL1e6-12   129MB/s ± 1%   129MB/s ± 1%     ~     (p=0.841 n=5+5)
EncodeTwainSL1e4-12   71.3MB/s ± 0%  72.2MB/s ± 2%     ~     (p=0.151 n=5+5)
EncodeTwainSL1e5-12    115MB/s ± 0%   116MB/s ± 0%   +0.95%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12    126MB/s ± 0%   126MB/s ± 0%   +0.54%  (p=0.032 n=5+5)

name                  old alloc/op   new alloc/op   delta
EncodeDigitsSL1e4-12    12.0kB ± 0%     0.0kB ± 0%  -99.72%  (p=0.008 n=5+5)
EncodeDigitsSL1e5-12    12.0kB ± 0%     0.0kB ± 0%  -99.68%  (p=0.008 n=5+5)
EncodeDigitsSL1e6-12    12.0kB ± 0%     0.1kB ± 0%  -99.23%  (p=0.008 n=5+5)
EncodeTwainSL1e4-12     12.0kB ± 0%     0.0kB ± 0%  -99.72%  (p=0.008 n=5+5)
EncodeTwainSL1e5-12     12.0kB ± 0%     0.0kB ± 0%  -99.68%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12     12.0kB ± 0%     0.1kB ± 0%  -99.22%  (p=0.008 n=5+5)

name                  old allocs/op  new allocs/op  delta
EncodeDigitsSL1e4-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeDigitsSL1e5-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeDigitsSL1e6-12      18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e4-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e5-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
EncodeTwainSL1e6-12       18.0 ± 0%       1.0 ± 0%  -94.44%  (p=0.008 n=5+5)
```
@klauspost klauspost merged commit c099ac9 into master Nov 22, 2019
@klauspost klauspost deleted the stateless-bitwriter-pool branch November 22, 2019 13:08
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.

1 participant