Apache Lucene open-source search software
LUCENE-6318: re-use immutable maps across fieldinfos when they are the same
Robert Muire4f06aba2da1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 23da1e1e5d6..425fcce8a39 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -128,6 +128,9 @@ Optimizationsrewrites to a BooleanQuery when the filter is a QueryWrapperFilter in orderto leverage approximations. (Adrien Grand)+* LUCENE-6318: Reduce RAM usage of FieldInfos when there are many fields.+ (Mike McCandless, Robert Muir)+API Changes* LUCENE-6204, LUCENE-6208: Simplify CompoundFormat: remove files()diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.javaindex 811aa6b6a1e..7c9fc0d2ffd 100755--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java@@ -120,6 +120,9 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {final int size = input.readVInt(); //read in the sizeinfos = new FieldInfo[size];+ // previous field's attribute map, we share when possible:+ Map<String,String> lastAttributes = Collections.emptyMap();+for (int i = 0; i < size; i++) {String name = input.readString();final int fieldNumber = input.readVInt();@@ -136,12 +139,17 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {// DV Types are packed in one bytefinal DocValuesType docValuesType = getDocValuesType(input, input.readByte());final long dvGen = input.readLong();- final Map<String,String> attributes;+ Map<String,String> attributes;if (format >= FORMAT_SAFE_MAPS) {attributes = input.readMapOfStrings();} else {attributes = Collections.unmodifiableMap(input.readStringStringMap());}+ // just use the last field's map if its the same+ if (attributes.equals(lastAttributes)) {+ attributes = lastAttributes;+ }+ lastAttributes = attributes;try {infos[i] = new FieldInfo(name, fieldNumber, storeTermVector, omitNorms, storePayloads,indexOptions, docValuesType, dvGen, attributes);