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

adding ability to use a cache with accessors #84

Merged
merged 42 commits into from
Dec 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
20f209e
draft
ptahmose Dec 2, 2023
a533f5a
cosmetic
ptahmose Dec 2, 2023
7f6c225
add subblock-cache to ISingleChannelScalingTileAccessor
ptahmose Dec 2, 2023
ed583b0
add caching to CSingleChannelPyramidLevelTileAccessor
ptahmose Dec 2, 2023
d5f7f9c
cosmetic
ptahmose Dec 2, 2023
e9880ac
update
ptahmose Dec 2, 2023
40c83e8
cosmetic
ptahmose Dec 2, 2023
2ba4c00
fix incompatibility with older GCC (8.3)
ptahmose Dec 2, 2023
eb0e357
update
ptahmose Dec 3, 2023
8503b5f
update
ptahmose Dec 3, 2023
8504141
update
ptahmose Dec 4, 2023
9362831
update
ptahmose Dec 4, 2023
53e5b6b
cosmetic
ptahmose Dec 4, 2023
3996d9f
cosmetic
ptahmose Dec 4, 2023
6d7254a
Merge branch 'main' into jbl/#77-caching
ptahmose Dec 4, 2023
4f4ea8d
bump version
ptahmose Dec 4, 2023
8033658
cosmetic, start with "plane-scan"
ptahmose Dec 4, 2023
27adf72
update
ptahmose Dec 5, 2023
3c9c4f4
update
ptahmose Dec 5, 2023
f594154
update
ptahmose Dec 5, 2023
a02b8ed
update - make option "cachesize" operational
ptahmose Dec 5, 2023
c3311b0
fix bug with parsing command line option "background"
ptahmose Nov 19, 2023
e1ee676
update
ptahmose Dec 5, 2023
8903ea7
cleanup
ptahmose Dec 5, 2023
74c0144
cosmetic
ptahmose Dec 5, 2023
9c87211
update
ptahmose Dec 5, 2023
57f9112
cosmetic
ptahmose Dec 5, 2023
4630017
review
ptahmose Dec 5, 2023
56d48b2
cosmetic
ptahmose Dec 5, 2023
b8f8bc5
cosmetic
ptahmose Dec 5, 2023
374c512
Merge branch 'main' into jbl/#77-caching
ptahmose Dec 5, 2023
a6aae3e
version-history
ptahmose Dec 5, 2023
a3d37bb
typo
ptahmose Dec 5, 2023
7903d4d
cosmetic
ptahmose Dec 5, 2023
94341a1
add unittest
ptahmose Dec 6, 2023
bcee426
linter
ptahmose Dec 6, 2023
a2cb3ed
documentation
ptahmose Dec 6, 2023
a9538f2
cosmetic
ptahmose Dec 6, 2023
14a1579
cosmetic
ptahmose Dec 6, 2023
5859a86
Update Src/libCZI/libCZI_Compositor.h
ptahmose Dec 6, 2023
2cdc5cf
REUSE
ptahmose Dec 6, 2023
5ebc905
review
ptahmose Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cosmetic
ptahmose committed Dec 4, 2023
commit 53e5b6bac1e232f946d04d4c4335cd4195fa85c0
16 changes: 16 additions & 0 deletions Src/libCZI/libCZI_Compositor.h
Original file line number Diff line number Diff line change
@@ -43,9 +43,25 @@ namespace libCZI
virtual ~ISubBlockCacheStatistics() = default;
};

/// Interface for a caching components (which can be used with the compositors). The intended use is as follows:
/// * Whenever the bitmap corresponding to a subblock (c.f. ISubBlock::CreateBitmap) is accessed, the bitmap may be added
/// to a cache object, where the subblock-index is the key.
/// * Whenever a bitmap is needed (for a given subblock-index), the cache object is first queried whether it contains the bitmap. If yes, then the bitmap
/// returned may be used instead of executing the subblock-read-and-decode operation.
/// In order to control the memory usage of the cache, the cache object must be pruned (i.e. subblocks are removed from the cache). Currently this means,
/// that the Prune-method must be called manually. The cache object does not do any pruning automatically.
ptahmose marked this conversation as resolved.
Show resolved Hide resolved
/// The operations of Adding, Querying and Pruning the cache object are thread-safe.
class ISubBlockCache : public ISubBlockCacheStatistics
{
public:
/// Options for controlling the prune operation. There are two metrics which can be used to control what
/// remains in the cache and what is discarded: the maximum memory usage (for all elements in the cache) and
/// the maximum number of sub-blocks. If the cache exceeds one of those limits, then elements are evicted from the cache
/// until both condions are met. Eviction is done in the order starting with elements where their last access is the longest
/// time ago. As "access" we define either the Add-operation or the Get-operation - so, when an element is retrieved from the
/// cache, it is considered as "accessed".
/// If only one condition is desired, then the other condition can be set to the maximum value of the respective type (which is the
/// default value).
struct PruneOptions
{
/// The maximum memory usage (in bytes) for the cache. If the cache exceeds this limit,
7 changes: 7 additions & 0 deletions Src/libCZI_UnitTests/test_SubBlockCache.cpp
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ TEST(SubBlockCache, GetStatistics)

TEST(SubBlockCache, PruneCacheCase1)
{
// We add two elements to the cache, making the last-added element the least recently used one. When then pruning the cache to 1 element,
// the first added element (with key=0) should be removed.
const auto cache = CreateSubBlockCache();
const auto bm1 = CreateTestBitmap(PixelType::Bgr24, 163, 128);
cache->Add(0, bm1);
@@ -104,6 +106,8 @@ TEST(SubBlockCache, PruneCacheCase1)

TEST(SubBlockCache, PruneCacheCase2)
{
// We add two items to the cache (with key 0, 1). Then, we retrieve element 0 from the cache, which makes it the least recently used one.
// When then pruning the cache to 1 element, element 1 should be removed.
const auto cache = CreateSubBlockCache();
const auto bm1 = CreateTestBitmap(PixelType::Bgr24, 163, 128);
cache->Add(0, bm1);
@@ -127,6 +131,9 @@ TEST(SubBlockCache, PruneCacheCase2)

TEST(SubBlockCache, PruneCacheCase3)
{
// We add three items to the cache (with key 0, 1, 2), each one byte in size. Then, we request to prune the cache
// to 1 byte max memory usage. This should remove the first two items from the cache (since they are the oldest entries),
// and keep the last one.
const auto cache = CreateSubBlockCache();
const auto bm1 = CreateTestBitmap(PixelType::Gray8, 1, 1);
cache->Add(0, bm1);