summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-12-04 09:59:06 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-12-04 09:59:06 +0000
commitf465b359ae3ef8d05f8f1cc5b98fc0d73753a8c8 (patch)
treecbc2aaa28b6641f58ed39564f7db219fd20d556e /searchlib
parent4c1c88213709ca0bd17cc2dd91db0e313724b4e8 (diff)
Pre allocate vector used as scratchpad.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h b/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h
index 964d9599b57..f4a5b0b8d0a 100644
--- a/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h
+++ b/searchlib/src/vespa/searchlib/features/tensor_from_attribute_executor.h
@@ -22,6 +22,7 @@ private:
const search::attribute::IAttributeVector *_attribute;
vespalib::eval::ValueType _type;
WeightedBufferType _attrBuffer;
+ std::vector<vespalib::stringref> _addr_ref;
std::unique_ptr<vespalib::eval::Value> _tensor;
public:
@@ -30,9 +31,11 @@ public:
: _attribute(attribute),
_type(vespalib::eval::ValueType::tensor_type({{dimension}})),
_attrBuffer(),
+ _addr_ref(),
_tensor()
{
_attrBuffer.allocate(_attribute->getMaxValueCount());
+ _addr_ref.reserve(1);
}
void execute(uint32_t docId) override;
};
@@ -44,12 +47,11 @@ TensorFromAttributeExecutor<WeightedBufferType>::execute(uint32_t docId)
_attrBuffer.fill(*_attribute, docId);
auto factory = FastValueBuilderFactory::get();
auto builder = factory.create_value_builder<double>(_type, 1, 1, _attrBuffer.size());
- std::vector<vespalib::stringref> addr_ref;
for (size_t i = 0; i < _attrBuffer.size(); ++i) {
vespalib::string label(_attrBuffer[i].value());
- addr_ref.clear();
- addr_ref.push_back(label);
- auto cell_array = builder->add_subspace(addr_ref);
+ _addr_ref.clear();
+ _addr_ref.push_back(label);
+ auto cell_array = builder->add_subspace(_addr_ref);
cell_array[0] = _attrBuffer[i].weight();
}
_tensor = builder->build(std::move(builder));