Skip to content

Commit

Permalink
Only consider raw proto object
Browse files Browse the repository at this point in the history
  • Loading branch information
finnegancarroll committed Oct 4, 2024
1 parent a448b31 commit e7eea5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.common.io.stream.BytesStreamInput;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.proto.search.SearchHitsProtoDef;
import org.opensearch.search.SearchHits;
import org.opensearch.transport.protobuf.SearchHitsProtobuf;

Expand All @@ -43,7 +45,7 @@
@State(Scope.Benchmark)
public class SearchHitsProtobufBenchmark {

List<SearchHitsProtobuf> searchHits = new ArrayList<>();
List<SearchHitsProtoDef.SearchHitsProto> searchHits = new ArrayList<>();

@Setup
public void setup() throws IOException {
Expand All @@ -54,7 +56,7 @@ public void setup() throws IOException {
InputStream in = Files.newInputStream(testFile);
BytesStreamInput sin = new BytesStreamInput(in.readAllBytes());
SearchHitsProtobuf testItem = new SearchHitsProtobuf(new SearchHits(sin));
searchHits.add(testItem);
searchHits.add(testItem.toProto());
}
}

Expand All @@ -70,10 +72,10 @@ public void setup() throws IOException {
@Benchmark
public List<XContentBuilder> toXContBench() throws IOException {
List<XContentBuilder> XContList = new ArrayList<>();
for (SearchHitsProtobuf sh : searchHits) {
for (SearchHitsProtoDef.SearchHitsProto sh : searchHits) {
XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject();
sh.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.rawField("protobuf", sh.toByteString().newInput(), MediaType.fromMediaType("application/octet-stream"));
builder.endObject();
XContList.add(builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

SearchHitsProto toProto() {
public SearchHitsProto toProto() {
SearchHitsProto.Builder builder = SearchHitsProto.newBuilder().setMaxScore(maxScore);

for (SearchHit hit : hits) {
Expand Down

0 comments on commit e7eea5a

Please sign in to comment.