aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-05-25 14:14:11 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-05-25 14:14:27 +0000
commit18a3749298480a2f188dce67adfd98d9a7621941 (patch)
tree0ac7358f5a0a39ed2d1c6a94bc252fa70068c800 /searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
parentd180f4be67f0d0ea0e5dc474de4cd08b2dd71c54 (diff)
- Use a rwlock as reading surpasses writing by a very large factor.
- size() does not need a lock.
Diffstat (limited to 'searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
index 3936fb2ee67..455c27459cd 100644
--- a/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
+++ b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
@@ -6,7 +6,8 @@
#include <vespa/vespalib/stllike/hash_map.h>
#include <vespa/vespalib/stllike/string.h>
#include <memory>
-#include <mutex>
+#include <shared_mutex>
+#include <atomic>
namespace search { class BitVector; }
namespace search::attribute {
@@ -22,7 +23,6 @@ public:
using ReadGuardSP = IDocumentMetaStoreContext::IReadGuard::SP;
struct Entry {
- using SP = std::shared_ptr<Entry>;
// We need to keep a document meta store read guard to ensure that no lids that are cached
// in the bit vector are re-used until the guard is released.
ReadGuardSP dmsReadGuard;
@@ -33,18 +33,18 @@ public:
};
private:
- using LockGuard = std::lock_guard<std::mutex>;
- using Cache = vespalib::hash_map<vespalib::string, Entry::SP>;
+ using Cache = vespalib::hash_map<vespalib::string, std::shared_ptr<Entry>>;
- mutable std::mutex _mutex;
+ mutable std::shared_mutex _mutex;
+ std::atomic<uint64_t> _size;
Cache _cache;
public:
BitVectorSearchCache();
~BitVectorSearchCache();
- void insert(const vespalib::string &term, Entry::SP entry);
- Entry::SP find(const vespalib::string &term) const;
- size_t size() const;
+ void insert(const vespalib::string &term, std::shared_ptr<Entry> entry);
+ std::shared_ptr<Entry> find(const vespalib::string &term) const;
+ size_t size() const { return _size.load(std::memory_order_relaxed); }
void clear();
};