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

Improve cachekv write performance #388

Merged
merged 2 commits into from
Jan 2, 2024
Merged

Improve cachekv write performance #388

merged 2 commits into from
Jan 2, 2024

Conversation

yzang2019
Copy link
Collaborator

@yzang2019 yzang2019 commented Dec 28, 2023

Describe your changes and provide context

This PR avoid the several O(N) operations to clear up the maps. Instead of looping through each item and delete them, it will be much more efficient to just reset to a new map.

Testing performed to validate your change

Tested in loadtest cluster and get performance improved (3ms -> 0.1ms)

Copy link

codecov bot commented Dec 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fe0738b) 54.81% compared to head (ed475a8) 54.80%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
- Coverage   54.81%   54.80%   -0.01%     
==========================================
  Files         622      622              
  Lines       52177    52168       -9     
==========================================
- Hits        28599    28590       -9     
  Misses      21495    21495              
  Partials     2083     2083              
Files Coverage Δ
store/cachekv/store.go 80.82% <100.00%> (-0.76%) ⬇️

@@ -135,18 +135,9 @@ func (store *Store) Write() {
// Clear the cache using the map clearing idiom
// and not allocating fresh objects.
// Please see https://bencher.orijtech.com/perfclinic/mapclearing/
store.cache.Range(func(key, value any) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

do these maps no longer behave in the idiomatic way? I gues that makes sense as we migrated from native go maps to sync maps, but just want to confirm

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, there's also a mutex to protect the writes

@@ -135,18 +135,9 @@ func (store *Store) Write() {
// Clear the cache using the map clearing idiom
Copy link
Contributor

Choose a reason for hiding this comment

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

(i think this comment can probably go away now - LGTM 👍)

@yzang2019 yzang2019 merged commit 31cfbd9 into main Jan 2, 2024
15 checks passed
@yzang2019 yzang2019 deleted the yzang/improve-cachekv branch January 2, 2024 16:27
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.

4 participants