From f5a24c0ffd9dbb2e4fa5a325562c5a016ed027e0 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Tue, 12 Jan 2021 14:25:31 +0000 Subject: avoid extra Value copy when updating DirectTensorAttribute --- .../src/vespa/searchlib/tensor/direct_tensor_attribute.cpp | 11 +++++++++++ .../src/vespa/searchlib/tensor/direct_tensor_attribute.h | 3 +++ searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp | 10 ++++++++++ searchlib/src/vespa/searchlib/tensor/tensor_attribute.h | 7 +++++-- 4 files changed, 29 insertions(+), 2 deletions(-) (limited to 'searchlib/src') 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 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 getTensor(DocId docId) const override; virtual bool onLoad() override; virtual std::unique_ptr 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 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 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 #include +#include -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. * -- cgit v1.2.3