From c65802a4b5811e890cc578afc3f651ec8835cd74 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Oct 2023 21:31:28 +0000 Subject: Document memory footprint of vespalib:.eval::FastValue --- eval/src/tests/eval/fast_value/fast_value_test.cpp | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 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..72c9df397de 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 #include #include +#include #include 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(); }; + auto addr = []() { return ConstArrayRef(); }; auto type = ValueType::from_spec("double"); - auto value = std::make_unique>(type, 0, 1, 1); + auto value = std::make_unique>(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)); + FastValue test(ValueType::from_spec("tensor(country{})"), 1, 1, 1); + EXPECT_EQ(340, test.get_memory_usage().allocatedBytes()); + + verifyFastValueSize(TensorSpec("tensor(country{})"), 1, 340); + verifyFastValueSize(TensorSpec("tensor(country{})"), 10, 720); + verifyFastValueSize(TensorSpec("tensor(country{})"), 20, 1208); + verifyFastValueSize(TensorSpec("tensor(country{})"), 50, 2224); + verifyFastValueSize(TensorSpec("tensor(country{})"), 100, 4216); +} + using SA = std::vector; TEST(FastValueBuilderTest, scalar_add_subspace_robustness) { -- cgit v1.2.3 From 87334d3bff77431a249e15c68182007ba7505534 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Oct 2023 21:46:57 +0000 Subject: Add dimension memory cost too. --- eval/src/tests/eval/fast_value/fast_value_test.cpp | 12 ++++++------ eval/src/vespa/eval/eval/fast_value.hpp | 3 ++- 2 files changed, 8 insertions(+), 7 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 72c9df397de..2332ab3bf8a 100644 --- a/eval/src/tests/eval/fast_value/fast_value_test.cpp +++ b/eval/src/tests/eval/fast_value/fast_value_test.cpp @@ -152,13 +152,13 @@ verifyFastValueSize(TensorSpec spec, uint32_t elems, size_t expected) { TEST(FastValueTest, document_fast_value_memory_usage) { EXPECT_EQ(232, sizeof(FastValue)); FastValue test(ValueType::from_spec("tensor(country{})"), 1, 1, 1); - EXPECT_EQ(340, test.get_memory_usage().allocatedBytes()); + EXPECT_EQ(412, test.get_memory_usage().allocatedBytes()); - verifyFastValueSize(TensorSpec("tensor(country{})"), 1, 340); - verifyFastValueSize(TensorSpec("tensor(country{})"), 10, 720); - verifyFastValueSize(TensorSpec("tensor(country{})"), 20, 1208); - verifyFastValueSize(TensorSpec("tensor(country{})"), 50, 2224); - verifyFastValueSize(TensorSpec("tensor(country{})"), 100, 4216); + verifyFastValueSize(TensorSpec("tensor(country{})"), 1, 412); + verifyFastValueSize(TensorSpec("tensor(country{})"), 10, 792); + verifyFastValueSize(TensorSpec("tensor(country{})"), 20, 1280); + verifyFastValueSize(TensorSpec("tensor(country{})"), 50, 2296); + verifyFastValueSize(TensorSpec("tensor(country{})"), 100, 4288); } using SA = std::vector; 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 { } MemoryUsage get_memory_usage() const override { MemoryUsage usage = self_memory_usage>(); + 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()); -- cgit v1.2.3