diff options
author | Geir Storli <geirst@yahooinc.com> | 2021-12-20 12:42:41 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2021-12-20 12:42:41 +0000 |
commit | eb6f2d54cd8aa1611772e2b7ad2ef1ad29d67132 (patch) | |
tree | f86eb4734b3a4be8c7f40baf08a1749ea466052b /searchlib | |
parent | 5a6fb96425ea47f9ba2c4a6e9294a53fc2fd3cb1 (diff) |
Optimize handling of CLEARDOC updates by caching the entry ref for the default value once.
Diffstat (limited to 'searchlib')
6 files changed, 23 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/changevector.h b/searchlib/src/vespa/searchlib/attribute/changevector.h index 014c218bc76..271497398a8 100644 --- a/searchlib/src/vespa/searchlib/attribute/changevector.h +++ b/searchlib/src/vespa/searchlib/attribute/changevector.h @@ -46,6 +46,7 @@ struct ChangeBase { uint32_t get_entry_ref() const { return _cached_entry_ref; } void set_entry_ref(uint32_t entry_ref) const { _cached_entry_ref = entry_ref; } bool has_entry_ref() const { return _cached_entry_ref != UNSET_ENTRY_REF; } + void clear_entry_ref() const { _cached_entry_ref = UNSET_ENTRY_REF; } Type _type; uint32_t _doc; diff --git a/searchlib/src/vespa/searchlib/attribute/enumattribute.h b/searchlib/src/vespa/searchlib/attribute/enumattribute.h index 8136e654152..f0ff23a06b4 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/enumattribute.h @@ -56,6 +56,7 @@ protected: virtual void considerAttributeChange(const Change & c, EnumStoreBatchUpdater & inserter) = 0; vespalib::MemoryUsage getEnumStoreValuesMemoryUsage() const override; void populate_address_space_usage(AddressSpaceUsage& usage) const override; + void cache_change_data_entry_ref(const Change& c) const; public: EnumAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & cfg); ~EnumAttribute(); diff --git a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp index 3e578856c2b..c0680fd9238 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/enumattribute.hpp @@ -84,6 +84,15 @@ EnumAttribute<B>::populate_address_space_usage(AddressSpaceUsage& usage) const usage.set(AddressSpaceComponents::enum_store, _enumStore.get_values_address_space_usage()); } +template <typename B> +void +EnumAttribute<B>::cache_change_data_entry_ref(const Change& c) const +{ + EnumIndex new_idx; + _enumStore.find_index(c._data.raw(), new_idx); + c.set_entry_ref(new_idx.ref()); +} + } // namespace search diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp index dc6db1d5a82..a51c9804cf2 100644 --- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.hpp @@ -181,6 +181,8 @@ void SingleValueEnumAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& updater) { ValueModifier valueGuard(this->getValueModifier()); + // This avoids searching for the defaultValue in the enum store for each CLEARDOC in the change vector. + this->cache_change_data_entry_ref(this->_defaultValue); for (const auto& change : this->_changes.getInsertOrder()) { if (change._type == ChangeBase::UPDATE) { applyUpdateValueChange(change, updater); @@ -192,6 +194,8 @@ SingleValueEnumAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& updater) applyUpdateValueChange(clearDoc, updater); } } + // We must clear the cached entry ref as the defaultValue might be located in another data buffer on later invocations. + this->_defaultValue.clear_entry_ref(); } template <typename B> diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp index 4d4e4619d51..4d37171e151 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp @@ -89,6 +89,8 @@ SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& // used to make sure several arithmetic operations on the same document in a single commit works std::map<DocId, EnumIndex> currEnumIndices; + // This avoids searching for the defaultValue in the enum store for each CLEARDOC in the change vector. + this->cache_change_data_entry_ref(this->_defaultValue); for (const auto& change : this->_changes.getInsertOrder()) { auto enumIter = currEnumIndices.find(change._doc); EnumIndex oldIdx; @@ -114,6 +116,8 @@ SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& applyUpdateValueChange(clearDoc, enumStore, currEnumIndices); } } + // We must clear the cached entry ref as the defaultValue might be located in another data buffer on later invocations. + this->_defaultValue.clear_entry_ref(); makePostingChange(enumStore.get_comparator(), currEnumIndices, changePost); diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp index 592ecb68b1e..4670ee075fe 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp @@ -90,6 +90,8 @@ SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater& // used to make sure several arithmetic operations on the same document in a single commit works std::map<DocId, EnumIndex> currEnumIndices; + // This avoids searching for the defaultValue in the enum store for each CLEARDOC in the change vector. + this->cache_change_data_entry_ref(this->_defaultValue); for (const auto& change : this->_changes.getInsertOrder()) { auto enumIter = currEnumIndices.find(change._doc); EnumIndex oldIdx; @@ -105,6 +107,8 @@ SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater& applyUpdateValueChange(this->_defaultValue, enumStore, currEnumIndices); } } + // We must clear the cached entry ref as the defaultValue might be located in another data buffer on later invocations. + this->_defaultValue.clear_entry_ref(); makePostingChange(enumStore.get_folded_comparator(), dictionary, currEnumIndices, changePost); |