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

store: discard unneeded information directly #4750

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

GiedriusS
Copy link
Member

@GiedriusS GiedriusS commented Oct 7, 2021

Discard unneeded data directly by calling Discard instead of copying to
io.Discard. The latter has a sync.Pool underneath from which it
retrieves byte slices into which data is read, and after that, it is
immediately discarded. So, save some time by just discarding unneeded
bytes directly.

Comparison:

name                            old time/op    new time/op    delta
BlockSeries/concurrency:_1-16     8.81ms ± 3%    8.35ms ± 7%  -5.26%  (p=0.000 n=69+76)
BlockSeries/concurrency:_2-16     4.76ms ± 5%    4.36ms ± 5%  -8.41%  (p=0.000 n=80+74)
BlockSeries/concurrency:_4-16     2.83ms ± 4%    2.70ms ± 6%  -4.82%  (p=0.000 n=77+80)
BlockSeries/concurrency:_8-16     2.24ms ± 7%    2.21ms ± 5%  -1.20%  (p=0.002 n=80+78)
BlockSeries/concurrency:_16-16    2.36ms ± 7%    2.24ms ± 8%  -5.29%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16    3.53ms ±10%    3.42ms ± 9%  -3.23%  (p=0.000 n=79+80)

name                            old alloc/op   new alloc/op   delta
BlockSeries/concurrency:_1-16     5.19MB ± 8%    5.17MB ± 5%    ~     (p=0.243 n=79+76)
BlockSeries/concurrency:_2-16     5.34MB ± 6%    5.27MB ± 8%  -1.31%  (p=0.006 n=79+79)
BlockSeries/concurrency:_4-16     5.28MB ±10%    5.28MB ± 9%    ~     (p=0.641 n=80+79)
BlockSeries/concurrency:_8-16     5.33MB ±12%    5.39MB ± 8%    ~     (p=0.143 n=80+77)
BlockSeries/concurrency:_16-16    6.39MB ± 9%    6.16MB ±12%  -3.66%  (p=0.000 n=75+78)
BlockSeries/concurrency:_32-16    9.20MB ±18%    9.03MB ±18%    ~     (p=0.061 n=79+80)

name                            old allocs/op  new allocs/op  delta
BlockSeries/concurrency:_1-16      31.6k ± 4%     31.7k ± 3%    ~     (p=0.325 n=80+76)
BlockSeries/concurrency:_2-16      31.9k ± 2%     30.9k ± 3%  -3.37%  (p=0.000 n=80+75)
BlockSeries/concurrency:_4-16      32.4k ± 3%     31.9k ± 4%  -1.39%  (p=0.000 n=80+80)
BlockSeries/concurrency:_8-16      32.2k ± 6%     32.5k ± 4%  +0.96%  (p=0.011 n=78+80)
BlockSeries/concurrency:_16-16     35.0k ± 7%     33.7k ± 8%  -3.70%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16     51.6k ± 8%     50.6k ±10%  -1.81%  (p=0.012 n=80+80)

Signed-off-by: Giedrius Statkevičius [email protected]

Discard unneeded data directly by calling Discard instead of copying to
`io.Discard`. The latter has a `sync.Pool` underneath from which it
retrieves byte slices into which data is read into, and after that it is
immediately discarded. So, save some time by just discarding unneeded
bytes directly.

Comparison:

```
name                            old time/op    new time/op    delta
BlockSeries/concurrency:_1-16     8.81ms ± 3%    8.35ms ± 7%  -5.26%  (p=0.000 n=69+76)
BlockSeries/concurrency:_2-16     4.76ms ± 5%    4.36ms ± 5%  -8.41%  (p=0.000 n=80+74)
BlockSeries/concurrency:_4-16     2.83ms ± 4%    2.70ms ± 6%  -4.82%  (p=0.000 n=77+80)
BlockSeries/concurrency:_8-16     2.24ms ± 7%    2.21ms ± 5%  -1.20%  (p=0.002 n=80+78)
BlockSeries/concurrency:_16-16    2.36ms ± 7%    2.24ms ± 8%  -5.29%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16    3.53ms ±10%    3.42ms ± 9%  -3.23%  (p=0.000 n=79+80)

name                            old alloc/op   new alloc/op   delta
BlockSeries/concurrency:_1-16     5.19MB ± 8%    5.17MB ± 5%    ~     (p=0.243 n=79+76)
BlockSeries/concurrency:_2-16     5.34MB ± 6%    5.27MB ± 8%  -1.31%  (p=0.006 n=79+79)
BlockSeries/concurrency:_4-16     5.28MB ±10%    5.28MB ± 9%    ~     (p=0.641 n=80+79)
BlockSeries/concurrency:_8-16     5.33MB ±12%    5.39MB ± 8%    ~     (p=0.143 n=80+77)
BlockSeries/concurrency:_16-16    6.39MB ± 9%    6.16MB ±12%  -3.66%  (p=0.000 n=75+78)
BlockSeries/concurrency:_32-16    9.20MB ±18%    9.03MB ±18%    ~     (p=0.061 n=79+80)

name                            old allocs/op  new allocs/op  delta
BlockSeries/concurrency:_1-16      31.6k ± 4%     31.7k ± 3%    ~     (p=0.325 n=80+76)
BlockSeries/concurrency:_2-16      31.9k ± 2%     30.9k ± 3%  -3.37%  (p=0.000 n=80+75)
BlockSeries/concurrency:_4-16      32.4k ± 3%     31.9k ± 4%  -1.39%  (p=0.000 n=80+80)
BlockSeries/concurrency:_8-16      32.2k ± 6%     32.5k ± 4%  +0.96%  (p=0.011 n=78+80)
BlockSeries/concurrency:_16-16     35.0k ± 7%     33.7k ± 8%  -3.70%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16     51.6k ± 8%     50.6k ±10%  -1.81%  (p=0.012 n=80+80)
```

Signed-off-by: Giedrius Statkevičius <[email protected]>
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GiedriusS GiedriusS merged commit e342026 into thanos-io:main Oct 8, 2021
@GiedriusS GiedriusS deleted the discard_directly branch October 8, 2021 08:28
GiedriusS added a commit to GiedriusS/thanos that referenced this pull request Oct 22, 2021
Discard unneeded data directly by calling Discard instead of copying to
`io.Discard`. The latter has a `sync.Pool` underneath from which it
retrieves byte slices into which data is read into, and after that it is
immediately discarded. So, save some time by just discarding unneeded
bytes directly.

Comparison:

```
name                            old time/op    new time/op    delta
BlockSeries/concurrency:_1-16     8.81ms ± 3%    8.35ms ± 7%  -5.26%  (p=0.000 n=69+76)
BlockSeries/concurrency:_2-16     4.76ms ± 5%    4.36ms ± 5%  -8.41%  (p=0.000 n=80+74)
BlockSeries/concurrency:_4-16     2.83ms ± 4%    2.70ms ± 6%  -4.82%  (p=0.000 n=77+80)
BlockSeries/concurrency:_8-16     2.24ms ± 7%    2.21ms ± 5%  -1.20%  (p=0.002 n=80+78)
BlockSeries/concurrency:_16-16    2.36ms ± 7%    2.24ms ± 8%  -5.29%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16    3.53ms ±10%    3.42ms ± 9%  -3.23%  (p=0.000 n=79+80)

name                            old alloc/op   new alloc/op   delta
BlockSeries/concurrency:_1-16     5.19MB ± 8%    5.17MB ± 5%    ~     (p=0.243 n=79+76)
BlockSeries/concurrency:_2-16     5.34MB ± 6%    5.27MB ± 8%  -1.31%  (p=0.006 n=79+79)
BlockSeries/concurrency:_4-16     5.28MB ±10%    5.28MB ± 9%    ~     (p=0.641 n=80+79)
BlockSeries/concurrency:_8-16     5.33MB ±12%    5.39MB ± 8%    ~     (p=0.143 n=80+77)
BlockSeries/concurrency:_16-16    6.39MB ± 9%    6.16MB ±12%  -3.66%  (p=0.000 n=75+78)
BlockSeries/concurrency:_32-16    9.20MB ±18%    9.03MB ±18%    ~     (p=0.061 n=79+80)

name                            old allocs/op  new allocs/op  delta
BlockSeries/concurrency:_1-16      31.6k ± 4%     31.7k ± 3%    ~     (p=0.325 n=80+76)
BlockSeries/concurrency:_2-16      31.9k ± 2%     30.9k ± 3%  -3.37%  (p=0.000 n=80+75)
BlockSeries/concurrency:_4-16      32.4k ± 3%     31.9k ± 4%  -1.39%  (p=0.000 n=80+80)
BlockSeries/concurrency:_8-16      32.2k ± 6%     32.5k ± 4%  +0.96%  (p=0.011 n=78+80)
BlockSeries/concurrency:_16-16     35.0k ± 7%     33.7k ± 8%  -3.70%  (p=0.000 n=78+76)
BlockSeries/concurrency:_32-16     51.6k ± 8%     50.6k ±10%  -1.81%  (p=0.012 n=80+80)
```

Signed-off-by: Giedrius Statkevičius <[email protected]>
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.

2 participants