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

Memcached: preallocate slice used for grouping cache keys by server #286

Merged
merged 1 commit into from
Apr 27, 2023

Conversation

56quarters
Copy link
Contributor

@56quarters 56quarters commented Apr 27, 2023

What this PR does:

We know the number of keys and so should preallocate the slice used. Runtime of both the new and old version varies by a lot however, the new version tends to be faster (in addition to consistently allocating less memory).

$ benchstat -delta-test=none old.txt new.txt 
name                                 old time/op    new time/op    delta
MemcachedClient_sortKeysByServer-16    2.53ms ± 0%    2.11ms ± 0%  -16.60%

name                                 old alloc/op   new alloc/op   delta
MemcachedClient_sortKeysByServer-16    1.31MB ± 0%    0.89MB ± 0%  -32.23%

name                                 old allocs/op  new allocs/op  delta
MemcachedClient_sortKeysByServer-16     20.1k ± 0%     20.1k ± 0%   -0.02%

Which issue(s) this PR fixes:

N/A

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
@56quarters 56quarters marked this pull request as ready for review April 27, 2023 15:10
@pracucci pracucci self-requested a review April 27, 2023 15:15
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Nice work!

@56quarters 56quarters merged commit 12cd006 into main Apr 27, 2023
@56quarters 56quarters deleted the 56quarters/sort-keys-prealloc branch April 27, 2023 15:30
56quarters added a commit to grafana/mimir that referenced this pull request Apr 27, 2023
Specifically, pulls in grafana/dskit#286

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
56quarters added a commit to grafana/mimir that referenced this pull request Apr 27, 2023
Specifically, pulls in grafana/dskit#286

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
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