Skip to content

Commit 262db33

Browse files
Optimize XContent Object Parsers (#78813) (#79673)
Optimize object parsers a little by extracting cold paths, removing some unnecessary lambda wrapping and some other small things. Also, fixed a very expensive use of these APIs in Phase moving from a very hot stream instantiation to a standard loop.
1 parent 26fbd0e commit 262db33

File tree

5 files changed

+159
-95
lines changed

5 files changed

+159
-95
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/AbstractObjectParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public <T> void declareField(BiConsumer<Value, T> consumer, CheckedFunction<XCon
156156
}
157157

158158
public <T> void declareObject(BiConsumer<Value, T> consumer, ContextParser<Context, T> objectParser, ParseField field) {
159-
declareField(consumer, (p, c) -> objectParser.parse(p, c), field, ValueType.OBJECT);
159+
declareField(consumer, objectParser, field, ValueType.OBJECT);
160160
}
161161

162162
/**
@@ -240,7 +240,7 @@ public void declareBoolean(BiConsumer<Value, Boolean> consumer, ParseField field
240240
}
241241

242242
public <T> void declareObjectArray(BiConsumer<Value, List<T>> consumer, ContextParser<Context, T> objectParser, ParseField field) {
243-
declareFieldArray(consumer, (p, c) -> objectParser.parse(p, c), field, ValueType.OBJECT_ARRAY);
243+
declareFieldArray(consumer, objectParser, field, ValueType.OBJECT_ARRAY);
244244
}
245245

246246
/**

libs/x-content/src/main/java/org/elasticsearch/xcontent/ConstructingObjectParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private class Target {
407407
/**
408408
* The parse context that is used for this invocation. Stored here so that it can be passed to the {@link #builder}.
409409
*/
410-
private Context context;
410+
private final Context context;
411411

412412
/**
413413
* How many of the constructor parameters have we collected? We keep track of this so we don't have to count the

0 commit comments

Comments
 (0)