diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-15 07:51:33 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-15 07:51:33 +0000 |
commit | 5343a9bea2b71203d3a804a9d6e04745723146cb (patch) | |
tree | 78965377886b78d3a16b1990445de84ff8c5c816 /searchlib | |
parent | b7fa88adf8cacacba2088d8532d79958182b1916 (diff) |
- Move when possible.
- Add noexcept to enable more movement
- Minor code cleanup.
Diffstat (limited to 'searchlib')
5 files changed, 55 insertions, 49 deletions
diff --git a/searchlib/src/tests/docstore/document_store/visitcache_test.cpp b/searchlib/src/tests/docstore/document_store/visitcache_test.cpp index 14e3c19fe33..3f80bb6004f 100644 --- a/searchlib/src/tests/docstore/document_store/visitcache_test.cpp +++ b/searchlib/src/tests/docstore/document_store/visitcache_test.cpp @@ -62,7 +62,7 @@ TEST("require that BlobSet can be built") { a.append(9, B("bbbbb",5)); verifyAB(a); CompressionConfig cfg(CompressionConfig::LZ4); - CompressedBlobSet ca(cfg, a); + CompressedBlobSet ca(cfg, std::move(a)); BlobSet b = ca.getBlobSet(); verifyAB(b); } diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 1080d44f2fb..1ca020bca86 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -368,13 +368,13 @@ TEST("test visit cache does not cache empty ones and is able to access some back IDataStore & datastore = store.getStore(); VisitCache visitCache(datastore, 100000, CompressionConfig::Type::LZ4); - EXPECT_EQUAL(0u, visitCache.read({1}).size()); + EXPECT_EQUAL(12u, visitCache.read({1}).byteSize()); EXPECT_TRUE(visitCache.read({1}).empty()); datastore.write(1,1, A7, 7); - EXPECT_EQUAL(0u, visitCache.read({2}).size()); + EXPECT_EQUAL(12u, visitCache.read({2}).byteSize()); CompressedBlobSet cbs = visitCache.read({1}); EXPECT_FALSE(cbs.empty()); - EXPECT_EQUAL(19u, cbs.size()); + EXPECT_EQUAL(19u, cbs.byteSize()); BlobSet bs(cbs.getBlobSet()); EXPECT_EQUAL(7u, bs.get(1).size()); EXPECT_EQUAL(0, strncmp(A7, bs.get(1).c_str(), 7)); @@ -664,14 +664,14 @@ TEST("test that the integrated visit cache works.") { vcs.remove(17); TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 104, 97, BASE_SZ-671)); vcs.verifyVisit({7,9,17,19,67,88,89}, {7,9,19,67,88,89}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 105, 98, BASE_SZ-89)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 105, 98, BASE_SZ-70)); vcs.verifyVisit({41, 42}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 106, 99, BASE_SZ+215)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 106, 99, BASE_SZ+230)); vcs.verifyVisit({43, 44}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 107, 100, BASE_SZ+520)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 107, 100, BASE_SZ+540)); vcs.verifyVisit({41, 42, 43, 44}, true); - TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 108, 99, BASE_SZ+340)); + TEST_DO(verifyCacheStats(ds.getCacheStats(), 101, 108, 99, BASE_SZ+360)); } TEST("testWriteRead") { diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp index 49beed34f08..7d585007d76 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp @@ -437,7 +437,8 @@ DocumentStore::getFileChunkStats() const return _backingStore.getFileChunkStats(); } -CacheStats DocumentStore::getCacheStats() const { +CacheStats +DocumentStore::getCacheStats() const { CacheStats visitStats = _visitCache->getCacheStats(); CacheStats singleStats = _cache->get_stats(); singleStats.add_extra_misses(_uncached_lookups.load(std::memory_order_relaxed)); diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index c99bb50d4f8..e9023c48ee5 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -17,14 +17,14 @@ using vespalib::DataBuffer; using vespalib::alloc::Alloc; using vespalib::alloc::MemoryAllocator; -KeySet::KeySet(uint32_t key) : - _keys() +KeySet::KeySet(uint32_t key) + : _keys() { _keys.push_back(key); } -KeySet::KeySet(const IDocumentStore::LidVector &keys) : - _keys(keys) +KeySet::KeySet(const IDocumentStore::LidVector &keys) + : _keys(keys) { std::sort(_keys.begin(), _keys.end()); } @@ -34,24 +34,25 @@ KeySet::contains(const KeySet &rhs) const { return std::includes(_keys.begin(), _keys.end(), rhs._keys.begin(), rhs._keys.end()); } -BlobSet::BlobSet() : - _positions(), - _buffer(Alloc::alloc(0, 16 * MemoryAllocator::HUGEPAGE_SIZE), 0) +BlobSet::BlobSet() + : _positions(), + _buffer(Alloc::alloc(0, 16 * MemoryAllocator::HUGEPAGE_SIZE), 0) { } BlobSet::~BlobSet() = default; namespace { -size_t getBufferSize(const BlobSet::Positions & p) { +size_t +getBufferSize(const BlobSet::Positions & p) { return p.empty() ? 0 : p.back().offset() + p.back().size(); } } -BlobSet::BlobSet(const Positions & positions, Alloc && buffer) : - _positions(positions), - _buffer(std::move(buffer), getBufferSize(_positions)) +BlobSet::BlobSet(Positions positions, Alloc && buffer) noexcept + : _positions(std::move(positions)), + _buffer(std::move(buffer), getBufferSize(_positions)) { } @@ -74,20 +75,19 @@ BlobSet::get(uint32_t lid) const return buf; } -CompressedBlobSet::CompressedBlobSet() : - _compression(CompressionConfig::Type::LZ4), - _positions(), - _buffer() +CompressedBlobSet::CompressedBlobSet() noexcept + : _compression(CompressionConfig::Type::LZ4), + _positions(), + _buffer() { } CompressedBlobSet::~CompressedBlobSet() = default; - -CompressedBlobSet::CompressedBlobSet(CompressionConfig compression, const BlobSet & uncompressed) : - _compression(compression.type), - _positions(uncompressed.getPositions()), - _buffer() +CompressedBlobSet::CompressedBlobSet(CompressionConfig compression, BlobSet uncompressed) + : _compression(compression.type), + _positions(uncompressed.stealPositions()), + _buffer() { if ( ! _positions.empty() ) { DataBuffer compressed; @@ -113,7 +113,8 @@ CompressedBlobSet::getBlobSet() const return BlobSet(_positions, std::move(uncompressed).stealBuffer()); } -size_t CompressedBlobSet::size() const { +size_t +CompressedBlobSet::byteSize() const { return _positions.capacity() * sizeof(BlobSet::Positions::value_type) + _buffer->size(); } @@ -122,13 +123,10 @@ namespace { class VisitCollector : public IBufferVisitor { public: - VisitCollector() : - _blobSet() - { } + VisitCollector(BlobSet & blobSet) : _blobSet(blobSet) { } void visit(uint32_t lid, ConstBufferRef buf) override; - const BlobSet & getBlobSet() const { return _blobSet; } private: - BlobSet _blobSet; + BlobSet & _blobSet; }; void @@ -142,9 +140,11 @@ VisitCollector::visit(uint32_t lid, ConstBufferRef buf) { bool VisitCache::BackingStore::read(const KeySet &key, CompressedBlobSet &blobs) const { - VisitCollector collector; + BlobSet blobSet; + blobSet.reserve(key.getKeys().size()); + VisitCollector collector(blobSet); _backingStore.read(key.getKeys(), collector); - blobs = CompressedBlobSet(_compression.load(std::memory_order_relaxed), collector.getBlobSet()); + blobs = CompressedBlobSet(_compression.load(std::memory_order_relaxed), std::move(blobSet)); return ! blobs.empty(); } @@ -237,8 +237,7 @@ VisitCache::Cache::removeKey(uint32_t subKey) { auto cacheGuard = getGuard(); const auto foundLid = _lid2Id.find(subKey); if (foundLid != _lid2Id.end()) { - K keySet = _id2KeySet[foundLid->second]; - invalidate(cacheGuard, keySet); + invalidate(cacheGuard, _id2KeySet[foundLid->second]); } } diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h index baa594b8d28..8b7ae5e6753 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.h +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h @@ -19,7 +19,7 @@ namespace search::docstore { **/ class KeySet { public: - KeySet() : _keys() { } + KeySet() noexcept : _keys() { } KeySet(uint32_t key); explicit KeySet(const IDocumentStore::LidVector &keys); uint32_t hash() const noexcept { return _keys.empty() ? 0 : _keys[0]; } @@ -51,12 +51,14 @@ public: using Positions = std::vector<LidPosition>; BlobSet(); - BlobSet(const Positions & positions, vespalib::alloc::Alloc && buffer); - BlobSet(BlobSet &&) = default; - BlobSet &operator = (BlobSet &&) = default; + BlobSet(Positions positions, vespalib::alloc::Alloc && buffer) noexcept; + BlobSet(BlobSet &&) noexcept = default; + BlobSet &operator = (BlobSet &&) noexcept = default; ~BlobSet(); + void reserve(size_t elems) { _positions.reserve(elems);} void append(uint32_t lid, vespalib::ConstBufferRef blob); const Positions & getPositions() const { return _positions; } + Positions && stealPositions() { return std::move(_positions); } vespalib::ConstBufferRef get(uint32_t lid) const; vespalib::ConstBufferRef getBuffer() const { return vespalib::ConstBufferRef(_buffer.data(), _buffer.size()); } private: @@ -73,14 +75,14 @@ private: class CompressedBlobSet { public: using CompressionConfig = vespalib::compression::CompressionConfig; - CompressedBlobSet(); - CompressedBlobSet(CompressionConfig compression, const BlobSet & uncompressed); - CompressedBlobSet(CompressedBlobSet && rhs) = default; - CompressedBlobSet & operator=(CompressedBlobSet && rhs) = default; + CompressedBlobSet() noexcept; + CompressedBlobSet(CompressionConfig compression, BlobSet uncompressed); + CompressedBlobSet(CompressedBlobSet && rhs) noexcept = default; + CompressedBlobSet & operator=(CompressedBlobSet && rhs) noexcept = default; CompressedBlobSet(const CompressedBlobSet & rhs) = default; CompressedBlobSet & operator=(const CompressedBlobSet & rhs) = default; ~CompressedBlobSet(); - size_t size() const; + size_t byteSize() const; bool empty() const { return _positions.empty(); } BlobSet getBlobSet() const; private: @@ -129,11 +131,15 @@ private: std::atomic<CompressionConfig> _compression; }; + struct ByteSize { + size_t operator() (const CompressedBlobSet & arg) const noexcept { return arg.byteSize(); } + }; + using CacheParams = vespalib::CacheParam< vespalib::LruParam<KeySet, CompressedBlobSet>, BackingStore, vespalib::zero<KeySet>, - vespalib::size<CompressedBlobSet> + ByteSize >; /** |