summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-10-24 21:31:28 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-10-24 21:31:28 +0000
commitc65802a4b5811e890cc578afc3f651ec8835cd74 (patch)
treea99b315575e5891b33e0eda886bd04930d70f640 /eval
parentc8562c7d04f66a4d8f8d32073e4b731f7f1b13a5 (diff)
Document memory footprint of vespalib:.eval::FastValue
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/fast_value/fast_value_test.cpp30
1 files 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 <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(340, test.get_memory_usage().allocatedBytes());
+
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 1, 340);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 10, 720);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 20, 1208);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 50, 2224);
+ verifyFastValueSize(TensorSpec("tensor<float>(country{})"), 100, 4216);
+}
+
using SA = std::vector<vespalib::stringref>;
TEST(FastValueBuilderTest, scalar_add_subspace_robustness) {