-
Notifications
You must be signed in to change notification settings - Fork 52
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
Allow cache to manage entries of varying size #1434
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1434 +/- ##
==========================================
- Coverage 89.63% 89.63% -0.01%
==========================================
Files 343 343
Lines 29951 29997 +46
Branches 3315 3322 +7
==========================================
+ Hits 26847 26887 +40
- Misses 1957 1959 +2
- Partials 1147 1151 +4 ☔ View full report in Codecov by Sentry. |
Quality Gate passedIssues Measures |
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.
Some minor improvements.
_totalSizeNonPinned = | ||
MemorySize::bytes(_totalSizeNonPinned.getBytes() - | ||
sizeInMap.getBytes() + newSize.getBytes()); |
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.
_totalSizeNonPinned = | |
MemorySize::bytes(_totalSizeNonPinned.getBytes() - | |
sizeInMap.getBytes() + newSize.getBytes()); | |
_totalSizeNonPinned = _totalSizeNonPinned- sizeInMap + newSize; |
- a short comment that we cannot use
+=
becauseMemorySize
can't (even temporarily) undeflow.
MemorySize::bytes(_totalSizeNonPinned.getBytes() - | ||
sizeInMap.getBytes() + newSize.getBytes()); | ||
sizeInMap = newSize; | ||
if (_totalSizePinned <= _maxSize) { |
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.
The if
is completely redundant and can be removed.
using Vec = std::vector<int>; | ||
[[maybe_unused]] auto vectorSizeGetter = [](const auto& pointer) { | ||
return pointer->size() * sizeof(int) * 1_B; | ||
}; | ||
|
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.
All such global stuff in .cpp files should be in the anonymous namespace { .... }
.
ASSERT_TRUE(cache.contains(1)); | ||
|
||
cache.recomputeSize(1); | ||
|
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.
Document here, why exactly which element is evicted.
/// and apply the diff to the internal size records. If the value grew too big | ||
/// for the cache in the meantime it is removed, if it grew but fits in the | ||
/// cache other values might be evicted instead. In case the value shrinks it | ||
/// is also removed because then it will be incomplete so it no longer makes | ||
/// sense to cache it. |
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.
Clarify that if it suffices, then other entries are evicted, only if this wouldn't suffice, the current entry itself is erased.
erase(key); | ||
return; | ||
} |
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.
It seems like the value has shrunk, delete it
case is missing!
Breakout part of #1350