summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-11-07 21:54:50 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-11-07 21:54:50 +0000
commitbbdb900d9d450515604c31192edf26a2d19e3d40 (patch)
treef8b70def82e7a3e144bb694a0b26d9a8c44d3f57
parentec06a46d765cb491e695b2c34eb6ed7264498337 (diff)
Reduce branch miss predictions.
-rw-r--r--eval/src/vespa/eval/eval/cell_type.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h25
-rw-r--r--searchlib/src/vespa/searchlib/tensor/vector_bundle.h4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.h8
4 files changed, 18 insertions, 25 deletions
diff --git a/eval/src/vespa/eval/eval/cell_type.cpp b/eval/src/vespa/eval/eval/cell_type.cpp
index aef5eee3e52..978aa55c088 100644
--- a/eval/src/vespa/eval/eval/cell_type.cpp
+++ b/eval/src/vespa/eval/eval/cell_type.cpp
@@ -1,12 +1,6 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "cell_type.h"
-#include <stdio.h>
-#include <cstdlib>
-#include <vespa/vespalib/util/exceptions.h>
-#include <vespa/vespalib/util/stringfmt.h>
-
-using vespalib::make_string_short::fmt;
namespace vespalib::eval {
diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h
index bd01703cd62..11bbf306b6d 100644
--- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h
+++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h
@@ -32,7 +32,7 @@ public:
vespalib::eval::CellType _cell_type;
size_t _aligned_size;
- TensorSizeCalc(const ValueType &type);
+ explicit TensorSizeCalc(const ValueType &type);
size_t bufSize() const {
return vespalib::eval::CellTypeUtils::mem_size(_cell_type, _numCells);
}
@@ -60,10 +60,10 @@ public:
DenseTensorStore(const ValueType &type, std::shared_ptr<vespalib::alloc::MemoryAllocator> allocator);
~DenseTensorStore() override;
- const ValueType &type() const { return _type; }
- size_t getNumCells() const { return _tensorSizeCalc._numCells; }
+ const ValueType &type() const noexcept { return _type; }
+ size_t getNumCells() const noexcept { return _tensorSizeCalc._numCells; }
size_t getBufSize() const { return _tensorSizeCalc.bufSize(); }
- const void *getRawBuffer(RefType ref) const {
+ const void *getRawBuffer(RefType ref) const noexcept {
return _store.getEntryArray<char>(ref, _bufferType.getArraySize());
}
vespalib::datastore::Handle<char> allocRawBuffer();
@@ -78,22 +78,21 @@ public:
const DenseTensorStore* as_dense() const override;
DenseTensorStore* as_dense() override;
- vespalib::eval::TypedCells get_typed_cells(EntryRef ref) const {
- if (!ref.valid()) {
+ vespalib::eval::TypedCells get_typed_cells(EntryRef ref) const noexcept {
+ if (!ref.valid()) [[unlikely]] {
return _empty.cells();
}
- return vespalib::eval::TypedCells(getRawBuffer(ref),
- _type.cell_type(), getNumCells());
+ return {getRawBuffer(ref), _type.cell_type(), getNumCells()};
}
- VectorBundle get_vectors(EntryRef ref) const {
- if (!ref.valid()) {
- return VectorBundle();
+ VectorBundle get_vectors(EntryRef ref) const noexcept {
+ if (!ref.valid()) [[unlikely]] {
+ return {};
}
- return VectorBundle(getRawBuffer(ref), 1, _subspace_type);
+ return {getRawBuffer(ref), 1, _subspace_type};
}
const SubspaceType& get_subspace_type() const noexcept { return _subspace_type; }
// The following methods are meant to be used only for unit tests.
- uint32_t getArraySize() const { return _bufferType.getArraySize(); }
+ uint32_t getArraySize() const noexcept { return _bufferType.getArraySize(); }
uint32_t get_max_buffer_entries() const noexcept { return _bufferType.get_max_entries(); }
};
diff --git a/searchlib/src/vespa/searchlib/tensor/vector_bundle.h b/searchlib/src/vespa/searchlib/tensor/vector_bundle.h
index 31139fb7713..7ff7ea943de 100644
--- a/searchlib/src/vespa/searchlib/tensor/vector_bundle.h
+++ b/searchlib/src/vespa/searchlib/tensor/vector_bundle.h
@@ -20,7 +20,7 @@ class VectorBundle
size_t _subspace_mem_size;
size_t _subspace_size;
public:
- VectorBundle()
+ VectorBundle() noexcept
: _data(nullptr),
_cell_type(vespalib::eval::CellType::DOUBLE),
_subspaces(0),
@@ -28,7 +28,7 @@ public:
_subspace_size(0)
{
}
- VectorBundle(const void *data, uint32_t subspaces, const SubspaceType& subspace_type)
+ VectorBundle(const void *data, uint32_t subspaces, const SubspaceType& subspace_type) noexcept
: _data(data),
_cell_type(subspace_type.cell_type()),
_subspaces(subspaces),
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.h b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
index 6af3f0ba034..bce2d2096f2 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.h
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
@@ -105,22 +105,22 @@ public:
void reclaim_all_memory();
template <typename EntryType, typename RefType>
- EntryType *getEntry(RefType ref) {
+ EntryType *getEntry(RefType ref) noexcept {
return static_cast<EntryType *>(_buffers[ref.bufferId()].get_buffer_relaxed()) + ref.offset();
}
template <typename EntryType, typename RefType>
- const EntryType *getEntry(RefType ref) const {
+ const EntryType *getEntry(RefType ref) const noexcept {
return static_cast<const EntryType *>(_buffers[ref.bufferId()].get_buffer_acquire()) + ref.offset();
}
template <typename EntryType, typename RefType>
- EntryType *getEntryArray(RefType ref, size_t arraySize) {
+ EntryType *getEntryArray(RefType ref, size_t arraySize) noexcept {
return static_cast<EntryType *>(_buffers[ref.bufferId()].get_buffer_relaxed()) + (ref.offset() * arraySize);
}
template <typename EntryType, typename RefType>
- const EntryType *getEntryArray(RefType ref, size_t arraySize) const {
+ const EntryType *getEntryArray(RefType ref, size_t arraySize) const noexcept {
return static_cast<const EntryType *>(_buffers[ref.bufferId()].get_buffer_acquire()) + (ref.offset() * arraySize);
}