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

Allow cache to manage entries of varying size #1434

Closed
wants to merge 1 commit into from

Conversation

RobinTF
Copy link
Collaborator

@RobinTF RobinTF commented Aug 2, 2024

Breakout part of #1350

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.63%. Comparing base (3fad814) to head (0235f59).

Files Patch % Lines
src/util/Cache.h 84.84% 0 Missing and 5 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Aug 2, 2024

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

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

Some minor improvements.

Comment on lines +258 to +260
_totalSizeNonPinned =
MemorySize::bytes(_totalSizeNonPinned.getBytes() -
sizeInMap.getBytes() + newSize.getBytes());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_totalSizeNonPinned =
MemorySize::bytes(_totalSizeNonPinned.getBytes() -
sizeInMap.getBytes() + newSize.getBytes());
_totalSizeNonPinned = _totalSizeNonPinned- sizeInMap + newSize;
  • a short comment that we cannot use += because MemorySize can't (even temporarily) undeflow.

MemorySize::bytes(_totalSizeNonPinned.getBytes() -
sizeInMap.getBytes() + newSize.getBytes());
sizeInMap = newSize;
if (_totalSizePinned <= _maxSize) {
Copy link
Member

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.

Comment on lines +16 to +20
using Vec = std::vector<int>;
[[maybe_unused]] auto vectorSizeGetter = [](const auto& pointer) {
return pointer->size() * sizeof(int) * 1_B;
};

Copy link
Member

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);

Copy link
Member

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.

Comment on lines +235 to +239
/// 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.
Copy link
Member

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.

Comment on lines +252 to +254
erase(key);
return;
}
Copy link
Member

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!

@RobinTF RobinTF closed this Aug 7, 2024
@RobinTF RobinTF deleted the varying-cache-changes branch August 23, 2024 16:56
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