Skip to content

Commit 46e42ce

Browse files
committed
Change
1 parent 5e4655c commit 46e42ce

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/eson/ESONDeserializationBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void readESON(Blackhole bh) throws IOException {
152152
source.length()
153153
)
154154
) {
155-
ESONSource.ESONObject eson = new ESONSource.Builder(refRecycler).parse(parser);
155+
ESONSource.ESONObject eson = new ESONSource.Builder().parse(parser);
156156
bh.consume(eson);
157157
}
158158
}

server/src/main/java/org/elasticsearch/action/index/IndexRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public IndexRequest source(BytesReference source, XContentType xContentType) {
564564
this.source = Objects.requireNonNull(source);
565565
this.contentType = Objects.requireNonNull(xContentType);
566566
if (useStructuredSource) {
567-
ESONSource.Builder builder = new ESONSource.Builder();
567+
ESONSource.Builder builder = new ESONSource.Builder((int) (source.length() * 0.70));
568568
try {
569569
XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, source, xContentType);
570570
structuredSource = builder.parse(parser);

server/src/main/java/org/elasticsearch/ingest/ESONSource.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ public static class Builder {
4040
private final List<KeyEntry> keyArray;
4141

4242
public Builder() {
43-
this(BytesRefRecycler.NON_RECYCLING_INSTANCE);
43+
this(0);
4444
}
4545

46-
public Builder(Recycler<BytesRef> refRecycler) {
47-
this.bytes = new BytesStreamOutput(128);
46+
public Builder(int expectedSize) {
47+
this(BytesRefRecycler.NON_RECYCLING_INSTANCE, expectedSize);
48+
}
49+
50+
public Builder(Recycler<BytesRef> refRecycler, int expectedSize) {
51+
this.bytes = new BytesStreamOutput(expectedSize);
4852
this.keyArray = new ArrayList<>();
4953
}
5054

server/src/main/java/org/elasticsearch/ingest/IngestService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,12 @@ static String getProcessorName(Processor processor) {
13411341
* Builds a new ingest document from the passed-in index request.
13421342
*/
13431343
private static IngestDocument newIngestDocument(final IndexRequest request) {
1344-
ESONSource.Builder builder = new ESONSource.Builder();
1344+
BytesReference source = request.source();
1345+
ESONSource.Builder builder = new ESONSource.Builder((int) (source.length() * 0.70));
13451346
try (
13461347
XContentParser parser = XContentHelper.createParser(
13471348
XContentParserConfiguration.EMPTY,
1348-
request.source(),
1349+
source,
13491350
request.getContentType()
13501351
);
13511352
) {

0 commit comments

Comments
 (0)