Skip to content

Commit

Permalink
Fix NumberFieldMapper Referencing its Own Builder (#77131) (#77168)
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 6ea1051 commit 841d2ca
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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<Map<String, String>> meta = Parameter.metaParam();
Expand Down Expand Up @@ -1065,7 +1065,6 @@ public CollapseType collapseType() {
}
}

private final Builder builder;
private final NumberType type;

private final boolean indexed;
Expand All @@ -1077,6 +1076,8 @@ public CollapseType collapseType() {
private final FieldValues<Number> scriptValues;
private final boolean ignoreMalformedByDefault;
private final boolean coerceByDefault;
private final ScriptCompiler scriptCompiler;
private final Script script;

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

boolean coerce() {
Expand Down Expand Up @@ -1170,6 +1172,6 @@ protected void indexScriptValues(SearchLookup searchLookup, LeafReaderContext re

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

0 comments on commit 841d2ca

Please sign in to comment.