You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/10/31 14:02:03 UTC

[21/50] [abbrv] lucene-solr:jira/solr-11285-sim: LUCENE-8018: FieldInfos retains garbage if non-sparse.

LUCENE-8018: FieldInfos retains garbage if non-sparse.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/401dda7e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/401dda7e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/401dda7e

Branch: refs/heads/jira/solr-11285-sim
Commit: 401dda7e064b6f621cba405985143724d79620c4
Parents: 0d29f7a
Author: Adrien Grand <jp...@gmail.com>
Authored: Fri Oct 27 08:36:27 2017 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Fri Oct 27 08:36:27 2017 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                           | 5 +++++
 lucene/core/src/java/org/apache/lucene/index/FieldInfos.java | 7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/401dda7e/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8d858e4..ea4b8be 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -31,6 +31,11 @@ Bug Fixes
   refreshes or commits, and high indexing thread counts, do not
   overflow an int (Mykhailo Demianenko via Mike McCandless)
 
+Optimizations
+
+* LUCENE-8018: Smaller FieldInfos memory footprint by not retaining unnecessary
+  references to TreeMap entries. (Julian Vassev via Adrien Grand)
+
 ======================= Lucene 7.1.0 =======================
 
 Changes in Runtime Behavior

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/401dda7e/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
index c73c9da..a7dc0b8 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
@@ -17,6 +17,7 @@
 package org.apache.lucene.index;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -95,14 +96,15 @@ public class FieldInfos implements Iterable<FieldInfo> {
     this.hasNorms = hasNorms;
     this.hasDocValues = hasDocValues;
     this.hasPointValues = hasPointValues;
-    this.values = Collections.unmodifiableCollection(byNumber.values());
-    Integer max = byNumber.isEmpty() ? null : Collections.max(byNumber.keySet());
+    Integer max = byNumber.isEmpty() ? null : byNumber.lastKey();
     
     // Only usee TreeMap in the very sparse case (< 1/16th of the numbers are used),
     // because TreeMap uses ~ 64 (32 bit JVM) or 120 (64 bit JVM w/o compressed oops)
     // overall bytes per entry, but array uses 4 (32 bit JMV) or 8
     // (64 bit JVM w/o compressed oops):
     if (max != null && max < ArrayUtil.MAX_ARRAY_LENGTH && max < 16L*byNumber.size()) {
+      // Pull infos into an arraylist to avoid holding a reference to the TreeMap
+      values = Collections.unmodifiableCollection(new ArrayList<>(byNumber.values()));
       byNumberMap = null;
       byNumberTable = new FieldInfo[max+1];
       for (Map.Entry<Integer,FieldInfo> entry : byNumber.entrySet()) {
@@ -110,6 +112,7 @@ public class FieldInfos implements Iterable<FieldInfo> {
       }
     } else {
       byNumberMap = byNumber;
+      values = Collections.unmodifiableCollection(byNumber.values());
       byNumberTable = null;
     }
   }