From 54ee1372c4254e185e83c8eb9329ace9704664c6 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 30 Sep 2024 09:27:36 +0200 Subject: 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 --- src/zenstore/cache/cachedisklayer.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/zenstore/cache/cachedisklayer.cpp') 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 ChunkIndexes : InlineBlockChunkIndexes) + OutReferences.reserve(OutReferences.size() + InlineKeys.size() + + StandaloneKeys.size()); // Make space for at least one attachment per record + + for (const std::vector& 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(AttachmentCount)); - NextPrecachedReferencesStart += AttachmentCount; + size_t AttachmentCount = OutReferences.size() - NextPrecachedReferencesStart; + if (AttachmentCount > 0) + { + Keys.push_back(InlineKeys[ChunkIndex]); + AttachmentCounts.push_back(gsl::narrow(AttachmentCount)); + NextPrecachedReferencesStart += AttachmentCount; + } } } }; -- cgit v1.2.3