aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-10-25 17:45:50 +0200
committerGitHub <noreply@github.com>2023-10-25 17:45:50 +0200
commitc98427805cfb336c147f737dbe1129c725f33b79 (patch)
tree00d261ce4e39653eff3d76d408b359631d7388c1
parent1b705748a73ba67ede8d33fcb7372544cbbd2dc2 (diff)
parent87334d3bff77431a249e15c68182007ba7505534 (diff)
Merge pull request #29087 from vespa-engine/balder/document-fast-value-memory-costv8.249.12
Balder/document fast value memory cost
-rw-r--r--eval/src/tests/eval/fast_value/fast_value_test.cpp30
-rw-r--r--eval/src/vespa/eval/eval/fast_value.hpp3
2 files changed, 29 insertions, 4 deletions
diff --git a/eval/src/tests/eval/fast_value/fast_value_test.cpp b/eval/src/tests/eval/fast_value/fast_value_test.cpp
index c734b11e2d3..2332ab3bf8a 100644
--- a/eval/src/tests/eval/fast_value/fast_value_test.cpp
+++ b/eval/src/tests/eval/fast_value/fast_value_test.cpp
@@ -4,9 +4,11 @@
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/eval/test/gen_spec.h>
+#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
using namespace vespalib;
+using namespace vespalib::make_string_short;
using namespace vespalib::eval;
using namespace vespalib::eval::test;
@@ -114,9 +116,9 @@ TEST(FastValueTest, insert_subspace) {
}
TEST(FastValueTest, insert_empty_subspace) {
- auto addr = [](){ return ConstArrayRef<string_id>(); };
+ auto addr = []() { return ConstArrayRef<string_id>(); };
auto type = ValueType::from_spec("double");
- auto value = std::make_unique<FastValue<double,true>>(type, 0, 1, 1);
+ auto value = std::make_unique<FastValue<double, true>>(type, 0, 1, 1);
EXPECT_EQ(value->index().size(), 0);
{
auto [cells, added] = value->insert_subspace(addr());
@@ -124,7 +126,8 @@ TEST(FastValueTest, insert_empty_subspace) {
EXPECT_EQ(value->index().size(), 1);
ASSERT_EQ(cells.size(), 1);
cells[0] = 10.0;
- }{
+ }
+ {
auto [cells, added] = value->insert_subspace(addr());
EXPECT_FALSE(added);
EXPECT_EQ(value->index().size(), 1);
@@ -137,6 +140,27 @@ TEST(FastValueTest, insert_empty_subspace) {
EXPECT_EQ(actual, expected);
}
+void
+verifyFastValueSize(TensorSpec spec, uint32_t elems, size_t expected) {
+ for (uint32_t i=0; i < elems; i++) {
+ spec.add({{"country", fmt("no%d", i)}}, 17.0);
+ }
+ auto value = value_from_spec(spec, FastValueBuilderFactory::get());
+ EXPECT_EQ(expected, value->get_memory_usage().allocatedBytes());
+}
+
+TEST(FastValueTest, document_fast_value_memory_usage) {
+ EXPECT_EQ(232, sizeof(FastValue<float,true>));
+ FastValue<float,true> test(ValueType::from_spec("tensor<float>(country{})"), 1, 1, 1);
+ EXPECT_EQ(412, test.get_memory_usage().allocatedBytes());
+
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 1, 412);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 10, 792);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 20, 1280);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 50, 2296);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 100, 4288);
+}
+
using SA = std::vector<vespalib::stringref>;
TEST(FastValueBuilderTest, scalar_add_subspace_robustness) {
diff --git a/eval/src/vespa/eval/eval/fast_value.hpp b/eval/src/vespa/eval/eval/fast_value.hpp
index 0ad5124a6c9..cc9eb663b76 100644
--- a/eval/src/vespa/eval/eval/fast_value.hpp
+++ b/eval/src/vespa/eval/eval/fast_value.hpp
@@ -36,7 +36,7 @@ struct FastCells {
size_t capacity;
size_t size;
mutable alloc::Alloc memory;
- FastCells(size_t initial_capacity);
+ explicit FastCells(size_t initial_capacity);
FastCells(const FastCells &) = delete;
FastCells & operator = (const FastCells &) = delete;
~FastCells();
@@ -184,6 +184,7 @@ struct FastValue final : Value, ValueBuilder<T> {
}
MemoryUsage get_memory_usage() const override {
MemoryUsage usage = self_memory_usage<FastValue<T,transient>>();
+ usage.merge(vector_extra_memory_usage(my_type.dimensions()));
usage.merge(vector_extra_memory_usage(get_view(my_handles)));
usage.merge(my_index.map.estimate_extra_memory_usage());
usage.merge(my_cells.estimate_extra_memory_usage());