aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-09-30 09:27:36 +0200
committerGitHub Enterprise <[email protected]>2024-09-30 09:27:36 +0200
commit54ee1372c4254e185e83c8eb9329ace9704664c6 (patch)
treea766c6bb340db9e26fe23247da7c5fce1fe39395 /src
parentFixing compilation errors with fmt v11 (#172) (diff)
downloadzen-54ee1372c4254e185e83c8eb9329ace9704664c6.tar.xz
zen-54ee1372c4254e185e83c8eb9329ace9704664c6.zip
optimize startup time (#175)
* use tsl::robin_set for BlockIndexSet don't calculate full block location when only block index is needed * don't copy visitor function * reserve space for attachments
Diffstat (limited to 'src')
-rw-r--r--src/zencore/compactbinary.cpp4
-rw-r--r--src/zencore/include/zencore/compactbinary.h8
-rw-r--r--src/zenstore/blockstore.cpp20
-rw-r--r--src/zenstore/cache/cachedisklayer.cpp23
-rw-r--r--src/zenstore/compactcas.cpp6
-rw-r--r--src/zenstore/include/zenstore/blockstore.h12
6 files changed, 32 insertions, 41 deletions
diff --git a/src/zencore/compactbinary.cpp b/src/zencore/compactbinary.cpp
index 029889e85..adccaba70 100644
--- a/src/zencore/compactbinary.cpp
+++ b/src/zencore/compactbinary.cpp
@@ -407,7 +407,7 @@ CbFieldView::CbFieldView(const void* DataPointer, CbFieldType FieldType)
}
void
-CbFieldView::IterateAttachments(std::function<void(CbFieldView)> Visitor) const
+CbFieldView::IterateAttachments(const std::function<void(CbFieldView)>& Visitor) const
{
switch (CbFieldTypeOps::GetType(Type))
{
@@ -1170,7 +1170,7 @@ template class TCbFieldIterator<CbField>;
template<typename FieldType>
void
-TCbFieldIterator<FieldType>::IterateRangeAttachments(std::function<void(CbFieldView)> Visitor) const
+TCbFieldIterator<FieldType>::IterateRangeAttachments(const std::function<void(CbFieldView)>& Visitor) const
{
if (CbFieldTypeOps::HasFieldType(FieldType::GetType()))
{
diff --git a/src/zencore/include/zencore/compactbinary.h b/src/zencore/include/zencore/compactbinary.h
index a8707ba2b..38918d80c 100644
--- a/src/zencore/include/zencore/compactbinary.h
+++ b/src/zencore/include/zencore/compactbinary.h
@@ -514,7 +514,7 @@ public:
ZENCORE_API std::string_view AsString(std::string_view Default = std::string_view());
ZENCORE_API std::u8string_view AsU8String(std::u8string_view Default = std::u8string_view());
- ZENCORE_API void IterateAttachments(std::function<void(CbFieldView)> Visitor) const;
+ ZENCORE_API void IterateAttachments(const std::function<void(CbFieldView)>& Visitor) const;
/** Access the field as an int8. Returns the provided default on error. */
inline int8_t AsInt8(int8_t Default = 0) { return AsInteger<int8_t>(Default); }
@@ -796,7 +796,7 @@ public:
ZENCORE_API void CopyRangeTo(MutableMemoryView Buffer) const;
/** Invoke the visitor for every attachment in the field range. */
- ZENCORE_API void IterateRangeAttachments(std::function<void(CbFieldView)> Visitor) const;
+ ZENCORE_API void IterateRangeAttachments(const std::function<void(CbFieldView)>& Visitor) const;
/** Create a view of every field in the range. */
inline MemoryView GetRangeView() const { return MemoryView(FieldType::GetView().GetData(), FieldsEnd); }
@@ -965,7 +965,7 @@ public:
ZENCORE_API void CopyTo(BinaryWriter& Ar) const;
///** Invoke the visitor for every attachment in the array. */
- inline void IterateAttachments(std::function<void(CbFieldView)> Visitor) const
+ inline void IterateAttachments(const std::function<void(CbFieldView)>& Visitor) const
{
CreateViewIterator().IterateRangeAttachments(Visitor);
}
@@ -1073,7 +1073,7 @@ public:
ZENCORE_API void CopyTo(BinaryWriter& Ar) const;
///** Invoke the visitor for every attachment in the object. */
- inline void IterateAttachments(std::function<void(CbFieldView)> Visitor) const
+ inline void IterateAttachments(const std::function<void(CbFieldView)>& Visitor) const
{
CreateViewIterator().IterateRangeAttachments(Visitor);
}
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 7c6677052..592d1c7fb 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -331,17 +331,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max
}
void
-BlockStore::BlockIndexSet::Add(uint32_t BlockIndex)
-{
- if (!std::binary_search(begin(BlockIndexes), end(BlockIndexes), BlockIndex))
- {
- auto It = std::lower_bound(begin(BlockIndexes), end(BlockIndexes), BlockIndex);
- BlockIndexes.insert(It, BlockIndex);
- }
-}
-
-void
-BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations)
+BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownBlocks)
{
ZEN_TRACE_CPU("BlockStore::SyncExistingBlocksOnDisk");
@@ -355,7 +345,7 @@ BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations)
DeleteBlocks.insert(It.first);
}
- for (const uint32_t BlockIndex : KnownLocations.GetBlockIndices())
+ for (const uint32_t BlockIndex : KnownBlocks)
{
DeleteBlocks.erase(BlockIndex);
if (auto It = m_ChunkBlocks.find(BlockIndex); It != m_ChunkBlocks.end() && !It->second.IsNull())
@@ -1968,9 +1958,9 @@ TEST_CASE("blockstore.clean.stray.blocks")
// Recreate a fake block for a missing chunk location
BlockStore::BlockIndexSet KnownBlocks;
- KnownBlocks.Add(FirstChunkLocation.BlockIndex);
- KnownBlocks.Add(SecondChunkLocation.BlockIndex);
- KnownBlocks.Add(ThirdChunkLocation.BlockIndex);
+ KnownBlocks.insert(FirstChunkLocation.BlockIndex);
+ KnownBlocks.insert(SecondChunkLocation.BlockIndex);
+ KnownBlocks.insert(ThirdChunkLocation.BlockIndex);
Store.SyncExistingBlocksOnDisk(KnownBlocks);
// We create a fake block for the location - we should still not be able to get the chunk
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp
index a4aa497c4..3fc4eca03 100644
--- a/src/zenstore/cache/cachedisklayer.cpp
+++ b/src/zenstore/cache/cachedisklayer.cpp
@@ -1136,8 +1136,8 @@ ZenCacheDiskLayer::CacheBucket::InitializeIndexFromDisk(RwLock::ExclusiveLockSco
}
else
{
- const BlockStoreLocation& BlockLocation = Location.GetBlockLocation(m_Configuration.PayloadAlignment);
- KnownBlocks.Add(BlockLocation.BlockIndex);
+ uint32_t BlockIndex = Location.Location.BlockLocation.GetBlockIndex();
+ KnownBlocks.insert(BlockIndex);
}
}
m_BlockStore.SyncExistingBlocksOnDisk(KnownBlocks);
@@ -3649,6 +3649,7 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
{
continue;
}
+
const IoHash& Key = Entry.first;
if (Loc.IsFlagSet(DiskLocation::kStandaloneFile))
{
@@ -3672,7 +3673,10 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
}
}
- for (std::vector<std::size_t> ChunkIndexes : InlineBlockChunkIndexes)
+ OutReferences.reserve(OutReferences.size() + InlineKeys.size() +
+ StandaloneKeys.size()); // Make space for at least one attachment per record
+
+ for (const std::vector<std::size_t>& ChunkIndexes : InlineBlockChunkIndexes)
{
ZEN_ASSERT(!ChunkIndexes.empty());
@@ -3694,12 +3698,15 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
auto CaptureAttachments = [&](size_t ChunkIndex, MemoryView Data) {
if (GetAttachments(Data))
{
- size_t AttachmentCount = OutReferences.size() - NextPrecachedReferencesStart;
- if (WriteMetaData && AttachmentCount > 0)
+ if (WriteMetaData)
{
- Keys.push_back(InlineKeys[ChunkIndex]);
- AttachmentCounts.push_back(gsl::narrow<uint32_t>(AttachmentCount));
- NextPrecachedReferencesStart += AttachmentCount;
+ size_t AttachmentCount = OutReferences.size() - NextPrecachedReferencesStart;
+ if (AttachmentCount > 0)
+ {
+ Keys.push_back(InlineKeys[ChunkIndex]);
+ AttachmentCounts.push_back(gsl::narrow<uint32_t>(AttachmentCount));
+ NextPrecachedReferencesStart += AttachmentCount;
+ }
}
}
};
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp
index 6af07a606..5fca3046c 100644
--- a/src/zenstore/compactcas.cpp
+++ b/src/zenstore/compactcas.cpp
@@ -1293,9 +1293,9 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
for (const auto& Entry : m_LocationMap)
{
- const BlockStoreDiskLocation& DiskLocation = m_Locations[Entry.second];
- BlockStoreLocation BlockLocation = DiskLocation.Get(m_PayloadAlignment);
- KnownBlocks.Add(BlockLocation.BlockIndex);
+ const BlockStoreDiskLocation& DiskLocation = m_Locations[Entry.second];
+ uint32_t BlockIndex = DiskLocation.GetBlockIndex();
+ KnownBlocks.insert(BlockIndex);
}
m_BlockStore.SyncExistingBlocksOnDisk(KnownBlocks);
diff --git a/src/zenstore/include/zenstore/blockstore.h b/src/zenstore/include/zenstore/blockstore.h
index 29c53cf22..5af9aeb10 100644
--- a/src/zenstore/include/zenstore/blockstore.h
+++ b/src/zenstore/include/zenstore/blockstore.h
@@ -8,6 +8,7 @@
ZEN_THIRD_PARTY_INCLUDES_START
#include <tsl/robin_map.h>
+#include <tsl/robin_set.h>
ZEN_THIRD_PARTY_INCLUDES_END
#include <unordered_set>
@@ -144,18 +145,11 @@ public:
void Initialize(const std::filesystem::path& BlocksBasePath, uint64_t MaxBlockSize, uint64_t MaxBlockCount);
- struct BlockIndexSet
- {
- void Add(uint32_t BlockIndex);
- std::span<const uint32_t> GetBlockIndices() const { return BlockIndexes; }
-
- private:
- std::vector<uint32_t> BlockIndexes;
- };
+ typedef tsl::robin_set<uint32_t> BlockIndexSet;
// Ask the store to create empty blocks for all locations that does not have a block
// Remove any block that is not referenced
- void SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations);
+ void SyncExistingBlocksOnDisk(const BlockIndexSet& KnownBlocks);
BlockEntryCountMap GetBlocksToCompact(const BlockUsageMap& BlockUsage, uint32_t BlockUsageThresholdPercent);
void Close();