lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1626242 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/automaton/ lucene/suggest/ lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/
Date Fri, 19 Sep 2014 15:05:13 GMT
Author: mikemccand
Date: Fri Sep 19 15:05:12 2014
New Revision: 1626242

URL: http://svn.apache.org/r1626242
Log:
LUCENE-5963: more efficient AnalyzingSuggester.replaceSep

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
    lucene/dev/branches/branch_5x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_5x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1626242&r1=1626241&r2=1626242&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Fri Sep 19 15:05:12 2014
@@ -166,6 +166,9 @@ Optimizations
 * LUCENE-5959: Don't allocate excess memory when building automaton in
   finish. (Markus Heiden via Mike McCandless)
 
+* LUCENE-5963: Reduce memory allocations in
+  AnalyzingSuggester. (Markus Heiden via Mike McCandless)
+
 Build
 
 * LUCENE-5909: Smoke tester now has better command line parsing and

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java?rev=1626242&r1=1626241&r2=1626242&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
Fri Sep 19 15:05:12 2014
@@ -334,6 +334,11 @@ public class Automaton {
     return nextState/2;
   }
 
+  /** How many transitions this automaton has. */
+  public int getNumTransitions() {
+    return nextTransition / 3;   
+  }
+  
   /** How many transitions this state has. */
   public int getNumTransitions(int state) {
     int count = states[2*state+1];
@@ -676,6 +681,20 @@ public class Automaton {
       transitions[nextTransition++] = max;
     }
 
+    /** Add a [virtual] epsilon transition between source and dest.
+     *  Dest state must already have all transitions added because this
+     *  method simply copies those same transitions over to source. */
+    public void addEpsilon(int source, int dest) {
+      for (int upto = 0; upto < nextTransition; upto += 4) {
+         if (transitions[upto] == dest) {
+            addTransition(source, transitions[upto + 1], transitions[upto + 2], transitions[upto
+ 3]);
+         }
+      }
+      if (isAccept(dest)) {
+        setAccept(source, true);
+      }
+    }
+
     /** Sorts transitions first then min label ascending, then
      *  max label ascending, then dest ascending */
     private final Sorter sorter = new InPlaceMergeSorter() {
@@ -797,10 +816,11 @@ public class Automaton {
     public void copy(Automaton other) {
       int offset = getNumStates();
       int otherNumStates = other.getNumStates();
-      for(int s=0;s<otherNumStates;s++) {
-        int newState = createState();
-        setAccept(newState, other.isAccept(s));
-      }
+
+      // Copy all states
+      copyStates(other);
+      
+      // Copy all transitions
       Transition t = new Transition();
       for(int s=0;s<otherNumStates;s++) {
         int count = other.initTransition(s, t);
@@ -810,5 +830,14 @@ public class Automaton {
         }
       }
     }
+
+    /** Copies over all states from other. */
+    public void copyStates(Automaton other) {
+      int otherNumStates = other.getNumStates();
+      for (int s = 0; s < otherNumStates; s++) {
+        int newState = createState();
+        setAccept(newState, other.isAccept(s));
+      }
+    }
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java?rev=1626242&r1=1626241&r2=1626242&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java
Fri Sep 19 15:05:12 2014
@@ -299,14 +299,10 @@ public class AnalyzingSuggester extends 
   // we were asked to preserve them:
   private Automaton replaceSep(Automaton a) {
 
-    Automaton result = new Automaton();
-
-    // Copy all states over
     int numStates = a.getNumStates();
-    for(int s=0;s<numStates;s++) {
-      result.createState();
-      result.setAccept(s, a.isAccept(s));
-    }
+    Automaton.Builder result = new Automaton.Builder(numStates, a.getNumTransitions());
+    // Copy all states over
+    result.copyStates(a);
 
     // Go in reverse topo sort so we know we only have to
     // make one pass:
@@ -342,9 +338,7 @@ public class AnalyzingSuggester extends 
       }
     }
 
-    result.finishState();
-
-    return result;
+    return result.finish();
   }
 
   /** Used by subclass to change the lookup automaton, if



Mime
View raw message