aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-05-21 20:26:24 +0200
committerGitHub <noreply@github.com>2023-05-21 20:26:24 +0200
commit7f0e6584f6e8f3e38e491494b0a7b24d37db4187 (patch)
treeb76b2600e88d58fbd9163805298c7602ffdf38ea
parent932b3cecfcc71408c9fe25bd23df992737e516a1 (diff)
parent79346d5d16c549347a15399505acaab96b4a5506 (diff)
Merge pull request #27144 from vespa-engine/balder/reduce-number-of-allocationsv8.165.119
Balder/reduce number of allocations
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp19
-rw-r--r--searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp8
-rw-r--r--searchlib/src/vespa/searchlib/fef/matchdatalayout.h9
-rw-r--r--searchlib/src/vespa/searchlib/query/tree/node.h1
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h1
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/searchable.h27
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h3
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp9
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h1
14 files changed, 63 insertions, 46 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
index eee2b7a7203..03e15830ac5 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp
@@ -30,21 +30,21 @@ struct Mixer {
}
Blueprint::UP mix(Blueprint::UP indexes) {
- if (attributes.get() == 0) {
- if (indexes.get() == 0) {
+ if ( ! attributes) {
+ if ( ! indexes) {
return std::make_unique<EmptyBlueprint>();
}
- return Blueprint::UP(std::move(indexes));
+ return indexes;
}
- if (indexes.get() == 0) {
+ if ( ! indexes) {
if (attributes->childCnt() == 1) {
return attributes->removeChild(0);
} else {
- return Blueprint::UP(std::move(attributes));
+ return std::move(attributes);
}
}
- attributes->addChild(Blueprint::UP(std::move(indexes)));
- return Blueprint::UP(std::move(attributes));
+ attributes->addChild(std::move(indexes));
+ return std::move(attributes);
}
};
@@ -88,6 +88,7 @@ private:
void buildEquiv(ProtonEquiv &n) {
double eqw = n.getWeight().percent();
FieldSpecBaseList specs;
+ specs.reserve(n.numFields());
for (size_t i = 0; i < n.numFields(); ++i) {
specs.add(n.field(i).fieldSpec());
}
@@ -123,9 +124,7 @@ private:
assert(field.getFieldId() != search::fef::IllegalFieldId);
assert(field.getHandle() != search::fef::IllegalHandle);
if (field.attribute_field) {
- FieldSpecList attrField;
- attrField.add(field.fieldSpec());
- mixer.addAttribute(_context.getAttributes().createBlueprint(_requestContext, attrField, n));
+ mixer.addAttribute(_context.getAttributes().createBlueprint(_requestContext, field.fieldSpec(), n));
} else {
indexFields.add(field.fieldSpec());
}
diff --git a/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp b/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp
index 99326b2c1e6..632bd422581 100644
--- a/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp
+++ b/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp
@@ -6,8 +6,7 @@
namespace search::fef {
MatchDataLayout::MatchDataLayout()
- : _numTermFields(0),
- _fieldIds()
+ : _fieldIds()
{
}
@@ -17,9 +16,8 @@ MatchDataLayout::~MatchDataLayout() = default;
MatchData::UP
MatchDataLayout::createMatchData() const
{
- assert(_numTermFields == _fieldIds.size());
- auto md = std::make_unique<MatchData>(MatchData::params().numTermFields(_numTermFields));
- for (size_t i = 0; i < _numTermFields; ++i) {
+ auto md = std::make_unique<MatchData>(MatchData::params().numTermFields(_fieldIds.size()));
+ for (size_t i = 0; i < _fieldIds.size(); ++i) {
md->resolveTermField(i)->setFieldId(_fieldIds[i]);
}
return md;
diff --git a/searchlib/src/vespa/searchlib/fef/matchdatalayout.h b/searchlib/src/vespa/searchlib/fef/matchdatalayout.h
index 05d25a322db..8f7717ce7ac 100644
--- a/searchlib/src/vespa/searchlib/fef/matchdatalayout.h
+++ b/searchlib/src/vespa/searchlib/fef/matchdatalayout.h
@@ -14,14 +14,16 @@ namespace search::fef {
class MatchDataLayout
{
private:
- uint32_t _numTermFields;
std::vector<uint32_t> _fieldIds;
-
public:
/**
* Create an empty object.
**/
MatchDataLayout();
+ MatchDataLayout(MatchDataLayout &&) noexcept = default;
+ MatchDataLayout & operator=(MatchDataLayout &&) noexcept = default;
+ MatchDataLayout(const MatchDataLayout &) = default;
+ MatchDataLayout & operator=(const MatchDataLayout &) = delete;
~MatchDataLayout();
/**
@@ -32,8 +34,9 @@ public:
**/
TermFieldHandle allocTermField(uint32_t fieldId) {
_fieldIds.push_back(fieldId);
- return _numTermFields++;
+ return _fieldIds.size() - 1;
}
+ void reserve(size_t sz) { _fieldIds.reserve(sz); }
/**
* Create a match data object with the layout described by this
diff --git a/searchlib/src/vespa/searchlib/query/tree/node.h b/searchlib/src/vespa/searchlib/query/tree/node.h
index af9925e2ea3..7123d52a503 100644
--- a/searchlib/src/vespa/searchlib/query/tree/node.h
+++ b/searchlib/src/vespa/searchlib/query/tree/node.h
@@ -22,4 +22,3 @@ class Node {
};
}
-
diff --git a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp
index d9338641a39..a2d244250cf 100644
--- a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp
@@ -75,13 +75,12 @@ CreateBlueprintVisitorHelper::handleNumberTermAsText(query::NumberTerm &n)
template <typename WS, typename NODE>
void
CreateBlueprintVisitorHelper::createWeightedSet(std::unique_ptr<WS> bp, NODE &n) {
- FieldSpecList fields;
+ bp->reserve(n.getNumTerms());
for (size_t i = 0; i < n.getNumTerms(); ++i) {
- fields.clear();
- fields.add(bp->getNextChildField(_field));
auto term = n.getAsString(i);
query::SimpleStringTerm node(term.first, n.getView(), 0, term.second); // TODO Temporary
- bp->addTerm(_searchable.createBlueprint(_requestContext, fields, node), term.second.percent());
+ FieldSpec field = bp->getNextChildField(_field);
+ bp->addTerm(_searchable.createBlueprint(_requestContext, field, node), term.second.percent());
}
setResult(std::move(bp));
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp
index 61b717b1104..de5bdc33e3c 100644
--- a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp
@@ -25,6 +25,13 @@ DotProductBlueprint::getNextChildField(const FieldSpec &outer)
}
void
+DotProductBlueprint::reserve(size_t num_children) {
+ _weights.reserve(num_children);
+ _terms.reserve(num_children);
+ _layout.reserve(num_children);
+}
+
+void
DotProductBlueprint::addTerm(Blueprint::UP term, int32_t weight)
{
HitEstimate childEst = term->getState().estimate();
@@ -41,8 +48,7 @@ DotProductBlueprint::addTerm(Blueprint::UP term, int32_t weight)
}
SearchIterator::UP
-DotProductBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda,
- bool) const
+DotProductBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda, bool) const
{
assert(tfmda.size() == 1);
assert(getState().numFields() == 1);
diff --git a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h
index 4ba59ba755f..2975958b5af 100644
--- a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h
@@ -26,6 +26,7 @@ public:
FieldSpec getNextChildField(const FieldSpec &outer);
// used by create visitor
+ void reserve(size_t num_children);
void addTerm(Blueprint::UP term, int32_t weight);
SearchIteratorUP createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda, bool strict) const override;
diff --git a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp
index af6b59dd6ca..384dc0cd227 100644
--- a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp
@@ -44,7 +44,7 @@ EquivBlueprint::EquivBlueprint(FieldSpecBaseList fields,
fef::MatchDataLayout subtree_mdl)
: ComplexLeafBlueprint(std::move(fields)),
_estimate(),
- _layout(subtree_mdl),
+ _layout(std::move(subtree_mdl)),
_terms(),
_exactness()
{
diff --git a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
index 3be28ab75de..9c3910b20f9 100644
--- a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp
@@ -3,8 +3,6 @@
#include "same_element_blueprint.h"
#include "same_element_search.h"
#include "field_spec.hpp"
-#include "andsearch.h"
-#include "emptysearch.h"
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/searchlib/attribute/searchcontextelementiterator.h>
#include <vespa/vespalib/objects/visit.hpp>
@@ -66,8 +64,7 @@ SameElementBlueprint::fetchPostings(const ExecuteInfo &execInfo)
std::unique_ptr<SameElementSearch>
SameElementBlueprint::create_same_element_search(search::fef::TermFieldMatchData& tfmd, bool strict) const
{
- fef::MatchDataLayout my_layout = _layout;
- fef::MatchData::UP md = my_layout.createMatchData();
+ fef::MatchData::UP md = _layout.createMatchData();
std::vector<ElementIterator::UP> children(_terms.size());
for (size_t i = 0; i < _terms.size(); ++i) {
const State &childState = _terms[i]->getState();
diff --git a/searchlib/src/vespa/searchlib/queryeval/searchable.h b/searchlib/src/vespa/searchlib/queryeval/searchable.h
index 2438cbf5a3b..a36a7f34e1c 100644
--- a/searchlib/src/vespa/searchlib/queryeval/searchable.h
+++ b/searchlib/src/vespa/searchlib/queryeval/searchable.h
@@ -22,23 +22,12 @@ class FieldSpecList;
**/
class Searchable
{
-protected:
- /**
- * Create a blueprint searching a single field.
- *
- * @return blueprint
- * @param requestContext that belongs to the query
- * @param field the field to search
- * @param term the query tree term
- **/
- virtual std::unique_ptr<Blueprint> createBlueprint(const IRequestContext & requestContext,
- const FieldSpec &field,
- const search::query::Node &term) = 0;
-
public:
using SP = std::shared_ptr<Searchable>;
Searchable() = default;
+ virtual ~Searchable() = default;
+
/**
* Create a blueprint searching a set of fields. The default
@@ -53,7 +42,17 @@ public:
virtual std::unique_ptr<Blueprint> createBlueprint(const IRequestContext & requestContext,
const FieldSpecList &fields,
const search::query::Node &term);
- virtual ~Searchable() = default;
+ /**
+ * Create a blueprint searching a single field.
+ *
+ * @return blueprint
+ * @param requestContext that belongs to the query
+ * @param field the field to search
+ * @param term the query tree term
+ **/
+ virtual std::unique_ptr<Blueprint> createBlueprint(const IRequestContext & requestContext,
+ const FieldSpec &field,
+ const search::query::Node &term) = 0;
};
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp
index fe212666ec9..b4b55098eaa 100644
--- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp
@@ -56,6 +56,12 @@ ParallelWeakAndBlueprint::getNextChildField(const FieldSpec &outer)
}
void
+ParallelWeakAndBlueprint::reserve(size_t num_children) {
+ _weights.reserve(num_children);
+ _terms.reserve(num_children);
+}
+
+void
ParallelWeakAndBlueprint::addTerm(Blueprint::UP term, int32_t weight)
{
HitEstimate childEst = term->getState().estimate();
@@ -78,6 +84,7 @@ ParallelWeakAndBlueprint::createLeafSearch(const search::fef::TermFieldMatchData
assert(tfmda.size() == 1);
fef::MatchData::UP childrenMatchData = _layout.createMatchData();
wand::Terms terms;
+ terms.reserve(_terms.size());
for (size_t i = 0; i < _terms.size(); ++i) {
const State &childState = _terms[i]->getState();
assert(childState.numFields() == 1);
diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h
index 1a481be5c32..a2c13f12485 100644
--- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h
@@ -44,7 +44,7 @@ public:
score_t scoreThreshold,
double thresholdBoostFactor,
uint32_t scoresAdjustFrequency);
- virtual ~ParallelWeakAndBlueprint() override;
+ ~ParallelWeakAndBlueprint() override;
const WeakAndHeap &getScores() const { return _scores; }
@@ -56,6 +56,7 @@ public:
FieldSpec getNextChildField(const FieldSpec &outer);
// Used by create visitor
+ void reserve(size_t num_children);
void addTerm(Blueprint::UP term, int32_t weight);
SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override;
diff --git a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp
index f855b72812a..ee55a89dcdc 100644
--- a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp
@@ -74,6 +74,13 @@ WeightedSetTermBlueprint::WeightedSetTermBlueprint(const FieldSpec &field)
WeightedSetTermBlueprint::~WeightedSetTermBlueprint() = default;
void
+WeightedSetTermBlueprint::reserve(size_t num_children) {
+ _weights.reserve(num_children);
+ _terms.reserve(num_children);
+ _layout.reserve(num_children);
+}
+
+void
WeightedSetTermBlueprint::addTerm(Blueprint::UP term, int32_t weight)
{
HitEstimate childEst = term->getState().estimate();
@@ -100,7 +107,7 @@ WeightedSetTermBlueprint::createLeafSearch(const fef::TermFieldMatchDataArray &t
// TODO: pass ownership with unique_ptr
children[i] = _terms[i]->createSearch(*md, true).release();
}
- return SearchIterator::UP(WeightedSetTermSearch::create(children, *tfmda[0], _children_field.isFilter(), _weights, std::move(md)));
+ return WeightedSetTermSearch::create(children, *tfmda[0], _children_field.isFilter(), _weights, std::move(md));
}
SearchIterator::UP
diff --git a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h
index 2a3db3ec52d..3827dc8a35f 100644
--- a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h
@@ -30,6 +30,7 @@ public:
FieldSpec getNextChildField(const FieldSpec &) { return _children_field; }
// used by create visitor
+ void reserve(size_t num_children);
void addTerm(Blueprint::UP term, int32_t weight);
SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override;