summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2021-01-14 10:20:26 +0100
committerGitHub <noreply@github.com>2021-01-14 10:20:26 +0100
commit6d193ddcd446f2efa10749ef3f94d68ed02c6bab (patch)
tree1e34aa2905a1d46da197322b4cc4cf21008c6384 /searchlib
parente9ac9678864ce02a8f68679f1f0d2404fa51e474 (diff)
parentf5a24c0ffd9dbb2e4fa5a325562c5a016ed027e0 (diff)
Merge pull request #16017 from vespa-engine/arnej/avoid-value-copy
avoid extra Value copy when updating DirectTensorAttribute
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h3
-rw-r--r--searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/tensor/tensor_attribute.h7
4 files changed, 29 insertions, 2 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp
index 8cda62682d0..f4010857c76 100644
--- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp
@@ -76,6 +76,17 @@ DirectTensorAttribute::setTensor(DocId lid, const vespalib::eval::Value &tensor)
set_tensor(lid, FastValueBuilderFactory::get().copy(tensor));
}
+void
+DirectTensorAttribute::update_tensor(DocId docId,
+ const document::TensorUpdate &update,
+ const vespalib::eval::Value &old_tensor)
+{
+ auto new_value = update.apply_to(old_tensor, FastValueBuilderFactory::get());
+ if (new_value) {
+ set_tensor(docId, std::move(new_value));
+ }
+}
+
std::unique_ptr<vespalib::eval::Value>
DirectTensorAttribute::getTensor(DocId docId) const
{
diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h
index a49b3c751d9..a87526342ef 100644
--- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h
+++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h
@@ -17,6 +17,9 @@ public:
DirectTensorAttribute(vespalib::stringref baseFileName, const Config &cfg);
virtual ~DirectTensorAttribute();
virtual void setTensor(DocId docId, const vespalib::eval::Value &tensor) override;
+ void update_tensor(DocId docId,
+ const document::TensorUpdate &update,
+ const vespalib::eval::Value &old_tensor) override;
virtual std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override;
virtual bool onLoad() override;
virtual std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override;
diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
index e0b21290284..f5de1de640f 100644
--- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
@@ -13,6 +13,7 @@
#include <vespa/eval/eval/value.h>
using document::TensorDataType;
+using document::TensorUpdate;
using document::WrongTensorTypeException;
using vespalib::eval::FastValueBuilderFactory;
using vespalib::eval::TensorSpec;
@@ -250,6 +251,15 @@ TensorAttribute::getRefCopy() const
return RefCopyVector(&_refVector[0], &_refVector[0] + size);
}
+void
+TensorAttribute::update_tensor(DocId docId,
+ const document::TensorUpdate &update,
+ const vespalib::eval::Value &old_tensor)
+{
+ auto new_value = update.apply_to(old_tensor, FastValueBuilderFactory::get());
+ setTensor(docId, *new_value);
+}
+
std::unique_ptr<PrepareResult>
TensorAttribute::prepare_set_tensor(DocId docid, const vespalib::eval::Value& tensor) const
{
diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
index 7abfe66a2e4..adb9e7bca8c 100644
--- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
+++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
@@ -7,8 +7,9 @@
#include "tensor_store.h"
#include <vespa/searchlib/attribute/not_implemented_attribute.h>
#include <vespa/vespalib/util/rcuvector.h>
+#include <vespa/document/update/tensor_update.h>
-namespace vespalib::eval { struct Value; }
+namespace vespalib::eval { struct Value; struct ValueBuilderFactory; }
namespace search::tensor {
@@ -58,7 +59,9 @@ public:
uint32_t getVersion() const override;
RefCopyVector getRefCopy() const;
virtual void setTensor(DocId docId, const vespalib::eval::Value &tensor) = 0;
-
+ virtual void update_tensor(DocId docId,
+ const document::TensorUpdate &update,
+ const vespalib::eval::Value &oldTensor);
/**
* Performs the prepare step in a two-phase operation to set a tensor for a document.
*