summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 00:56:08 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 00:56:08 +0200
commitd81ca5ed1e254bc0dc4fe33a00d7ac641d9715aa (patch)
treeaa2e717c05907178e61fbf56d9a2dc29104548c8 /container-search
parent4cf6952345ac2fdcb9b14f1dc875a17d4fa2796d (diff)
- Presize array to its max size.
- Return the GrowableByteBuffer from TypedBinaryFormat instead of a copy of the buffer. Then buffer is copied only once instead of twice.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java
index 5e423a51b7a..3a9568a7370 100644
--- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java
+++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java
@@ -4,6 +4,7 @@ package com.yahoo.search.dispatch.rpc;
import ai.vespa.searchlib.searchprotocol.protobuf.SearchProtocol.StringProperty;
import ai.vespa.searchlib.searchprotocol.protobuf.SearchProtocol.TensorProperty;
import com.google.protobuf.ByteString;
+import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.serialization.TypedBinaryFormat;
@@ -51,12 +52,12 @@ public class MapConverter {
for (var entry : map.entrySet()) {
if (entry.getValue() != null) {
var key = entry.getKey();
- var stringValues = new ArrayList<String>();
+ var stringValues = new ArrayList<String>(entry.getValue().size());
for (var value : entry.getValue()) {
if (value != null) {
if (value instanceof Tensor tensor) {
- byte[] encoded = TypedBinaryFormat.encode(tensor);
- tensorInserter.accept(TensorProperty.newBuilder().setName(key).setValue(ByteString.copyFrom(encoded)));
+ var buffer = TypedBinaryFormat.encode(tensor, new GrowableByteBuffer(4096));
+ tensorInserter.accept(TensorProperty.newBuilder().setName(key).setValue(ByteString.copyFrom(buffer.getByteBuffer().flip())));
} else {
stringValues.add(value.toString());
}