From 1bd5cb6fb09dfa56a7b317a56a9914609f2b4535 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 27 Nov 2024 12:52:25 +0100 Subject: use plain sorted array instead of map of vectors (#237) * use plain sorted array instead of map of vectors * reserve vectors up front = 5% perf increase * don't do batch read of chunks if we have a single chunk -> 1% perf gain --- src/zenstore/compactcas.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/zenstore/compactcas.cpp') diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index 792854af6..9982e7571 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -308,9 +308,10 @@ CasContainerStrategy::IterateChunks(std::span ChunkHashes, WorkerThreadPool* OptionalWorkerPool, uint64_t LargeSizeLimit) { - if (ChunkHashes.size() < 3) + const size_t ChunkCount = ChunkHashes.size(); + if (ChunkCount < 3) { - for (size_t ChunkIndex = 0; ChunkIndex < ChunkHashes.size(); ChunkIndex++) + for (size_t ChunkIndex = 0; ChunkIndex < ChunkCount; ChunkIndex++) { IoBuffer Chunk = FindChunk(ChunkHashes[ChunkIndex]); if (!AsyncCallback(ChunkIndex, Chunk)) @@ -322,8 +323,10 @@ CasContainerStrategy::IterateChunks(std::span ChunkHashes, } std::vector FoundChunkIndexes; std::vector FoundChunkLocations; - RwLock::SharedLockScope _(m_LocationMapLock); - for (size_t ChunkIndex = 0; ChunkIndex < ChunkHashes.size(); ChunkIndex++) + FoundChunkIndexes.reserve(ChunkCount); + FoundChunkLocations.reserve(ChunkCount); + RwLock::SharedLockScope _(m_LocationMapLock); + for (size_t ChunkIndex = 0; ChunkIndex < ChunkCount; ChunkIndex++) { if (auto KeyIt = m_LocationMap.find(ChunkHashes[ChunkIndex]); KeyIt != m_LocationMap.end()) { -- cgit v1.2.3