-
Notifications
You must be signed in to change notification settings - Fork 522
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
Perf(common): optimize cache promotion and demotion #2949
Merged
wuhongsong
merged 2 commits into
opencurve:master
from
zztaki:optimize-cache-promotion-demotion
Jan 2, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,7 @@ class LRUCache : public LRUCacheInterface<K, V> { | |
void Remove(const K &key) override; | ||
|
||
/* | ||
* @brief Get the first key that $value = value | ||
* @brief Get the first key that $value = value from lru tail to head | ||
* | ||
* @param[in] value | ||
* @param[out] key | ||
|
@@ -429,10 +429,7 @@ void LRUCache<K, V, KeyTraits, ValueTraits>::RemoveLocked(const K &key) { | |
template <typename K, typename V, typename KeyTraits, typename ValueTraits> | ||
void LRUCache<K, V, KeyTraits, ValueTraits>::MoveToFront( | ||
const typename std::list<Item>::iterator &elem) { | ||
Item duplica{elem->key, elem->value}; | ||
ll_.erase(elem); | ||
ll_.push_front(duplica); | ||
cache_[*(duplica.key)] = ll_.begin(); | ||
ll_.splice(ll_.begin(), ll_, elem); | ||
} | ||
|
||
template <typename K, typename V, typename KeyTraits, typename ValueTraits> | ||
|
@@ -699,16 +696,8 @@ bool SglLRUCache<K, KeyTraits>::MoveBack(const K &key) { | |
if (iter == cache_.end()) { | ||
return false; | ||
} | ||
// delete the old value | ||
RemoveElement(iter->second); | ||
// put new value at tail | ||
ll_.push_back(key); | ||
cache_[key] = --ll_.end(); | ||
size_++; | ||
if (cacheMetrics_ != nullptr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why delete these lines? |
||
cacheMetrics_->UpdateAddToCacheCount(); | ||
cacheMetrics_->UpdateAddToCacheBytes(KeyTraits::CountBytes(key)); | ||
} | ||
// move key to list tail | ||
ll_.splice(ll_.end(), ll_, iter->second); | ||
return true; | ||
} | ||
|
||
|
@@ -806,10 +795,7 @@ void SglLRUCache<K, KeyTraits>::RemoveLocked(const K &key) { | |
template <typename K, typename KeyTraits> | ||
void SglLRUCache<K, KeyTraits>::MoveToFront( | ||
const typename std::list<K>::iterator &elem) { | ||
K tmp = *elem; | ||
ll_.erase(elem); | ||
ll_.emplace_front(tmp); | ||
cache_[tmp] = ll_.begin(); | ||
ll_.splice(ll_.begin(), ll_, elem); | ||
} | ||
|
||
template <typename K, typename KeyTraits> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function also include some metrics code, maybe you should consider it?