Skip to content

Commit

Permalink
Fix NumberFieldMapper Referencing its Own Builder (#77131)
Browse files Browse the repository at this point in the history
Investigating the heap use of mapper instances I found this.
It seems quite a bit of overhead for these instances goes into
the builder field. In other mappers we retain the script service
and the script outright, so I did the same thing here to make these
instances a little smaller.
  • Loading branch information
original-brownbear authored Sep 2, 2021
1 parent 27062e5 commit c082c25
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static class Builder extends FieldMapper.Builder {

private final Parameter<Number> nullValue;

private final Parameter<Script> script = Parameter.scriptParam(m -> toType(m).builder.script.get());
private final Parameter<Script> script = Parameter.scriptParam(m -> toType(m).script);
private final Parameter<String> onScriptError = Parameter.onScriptErrorParam(m -> toType(m).onScriptError, script);
private final Parameter<Boolean> dimension;

Expand Down Expand Up @@ -1084,7 +1084,6 @@ public boolean isDimension() {
}
}

private final Builder builder;
private final NumberType type;

private final boolean indexed;
Expand All @@ -1097,6 +1096,8 @@ public boolean isDimension() {
private final boolean ignoreMalformedByDefault;
private final boolean coerceByDefault;
private final boolean dimension;
private final ScriptCompiler scriptCompiler;
private final Script script;

private NumberFieldMapper(
String simpleName,
Expand All @@ -1116,7 +1117,8 @@ private NumberFieldMapper(
this.coerceByDefault = builder.coerce.getDefaultValue().value();
this.scriptValues = builder.scriptValues();
this.dimension = builder.dimension.getValue();
this.builder = builder;
this.scriptCompiler = builder.scriptCompiler;
this.script = builder.script.getValue();
}

boolean coerce() {
Expand Down Expand Up @@ -1203,7 +1205,7 @@ protected void indexScriptValues(SearchLookup searchLookup, LeafReaderContext re

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), type, builder.scriptCompiler, ignoreMalformedByDefault, coerceByDefault)
return new Builder(simpleName(), type, scriptCompiler, ignoreMalformedByDefault, coerceByDefault)
.dimension(dimension).init(this);
}
}

0 comments on commit c082c25

Please sign in to comment.