[Mulgara-svn] r861 - projects/xa2/object-pool/src

andrae at mulgara.org andrae at mulgara.org
Mon Apr 28 12:16:19 UTC 2008


Author: andrae
Date: 2008-04-28 05:16:15 -0700 (Mon, 28 Apr 2008)
New Revision: 861

Modified:
   projects/xa2/object-pool/src/CompBlockTrieTest.java
   projects/xa2/object-pool/src/CompMemTrie.java
   projects/xa2/object-pool/src/MemoryTrieTest.java
Log:
More elimination of exceptions.  Top performance hogs are now memory allocation
and IO.  It's not worth addressing these until we have a fuller picture of
memory/IO use.



Modified: projects/xa2/object-pool/src/CompBlockTrieTest.java
===================================================================
--- projects/xa2/object-pool/src/CompBlockTrieTest.java	2008-04-28 10:57:20 UTC (rev 860)
+++ projects/xa2/object-pool/src/CompBlockTrieTest.java	2008-04-28 12:16:15 UTC (rev 861)
@@ -22,19 +22,19 @@
  */
 public class CompBlockTrieTest {
   public static void main(String[] args) throws Exception {
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 1);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 2);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 3);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 4);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 5);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 6);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 7);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 8);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 9);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), 10);
-    testWithLimitedFile(new File("../scratch/propernames.uniq"), Integer.MAX_VALUE);
-    testWithLimitedFile(new File("../scratch/connectives.uniq"), Integer.MAX_VALUE);
-    testWithLimitedFile(new File("../scratch/web2a.uniq"), Integer.MAX_VALUE);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 1);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 2);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 3);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 4);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 5);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 6);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 7);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 8);
+ //   testWithLimitedFile(new File("../scratch/propernames.uniq"), 9);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), 10);
+//    testWithLimitedFile(new File("../scratch/propernames.uniq"), Integer.MAX_VALUE);
+//    testWithLimitedFile(new File("../scratch/connectives.uniq"), Integer.MAX_VALUE);
+//    testWithLimitedFile(new File("../scratch/web2a.uniq"), Integer.MAX_VALUE);
     testWithLimitedFile(new File("../scratch/web2.uniq"), Integer.MAX_VALUE);
 //    testWithRandomFileTuned(new File("../bulk/random70M"), 12, 10);
 //    testWithRandomFileTuned(new File("../bulk/random70M"), 250, 10);
@@ -105,31 +105,31 @@
     }
 
     long _endRead = System.currentTimeMillis();
-    
+
     System.out.println("Checking lines from " + file);
     long _startLookup = System.currentTimeMillis();
 
+    boolean[] valid = new boolean[1];
+
     for (byte[] key : namesMap.keySet()) {
       boolean found = false;
       for (CompBlockTrie t : tries) {
-        try {
-          if (t.lookup(key) == namesMap.get(key)) {
-            found = true;
-            break;
-          }
-        } catch (CompMemTrie.NotFound nf) {}
+        long value = t.lookup(key, valid);
+        if (valid[0] && value == namesMap.get(key)) {
+          found = true;
+          break;
+        }
       }
       if (!found) {
         throw new IllegalStateException("Trie doesn't match Map");
       }
       found = false;
       for (CompBlockTrie t : readTries) {
-        try {
-          if (t.lookup(key) == namesMap.get(key)) {
-            found = true;
-            break;
-          }
-        } catch (CompMemTrie.NotFound nf) {}
+        long value = t.lookup(key, valid);
+        if (valid[0] && value == namesMap.get(key)) {
+          found = true;
+          break;
+        }
       }
       if (!found) {
         throw new IllegalStateException("Read-Trie doesn't match Map");
@@ -137,7 +137,7 @@
     }
 
     long _endLookup = System.currentTimeMillis();
-    
+
     System.out.println("Test Succeeded with " + file +
         " insert:" + (_endInsert - _startInsert) + 
         " read:" + (_endRead - _startRead) + 

Modified: projects/xa2/object-pool/src/CompMemTrie.java
===================================================================
--- projects/xa2/object-pool/src/CompMemTrie.java	2008-04-28 10:57:20 UTC (rev 860)
+++ projects/xa2/object-pool/src/CompMemTrie.java	2008-04-28 12:16:15 UTC (rev 861)
@@ -18,6 +18,8 @@
 public class CompMemTrie {
   @SuppressWarnings("serial")
   public static class NotFound extends Exception {};
+  private static NotFound notfound = new NotFound();
+
   @SuppressWarnings("serial")
   public static class InsufficientSpace extends Exception
       { public InsufficientSpace(String s) { super(s); } };
@@ -48,11 +50,23 @@
   }
 
   public long lookup(byte[] key) throws NotFound {
+    boolean[] valid = new boolean[1];
+    long result = lookup(key, valid);
+    if (valid[0]) {
+      return result;
+    } else {
+      throw notfound;
+    }
+  }
+      
+
+  public long lookup(byte[] key, boolean[] valid) {
     if (root == null) {
-      throw new NotFound();
+      valid[0] = false;
+      return 0;
+    } else {
+      return root.lookup(key, valid);
     }
-
-    return root.lookup(key);
   }
 
   public void write(ByteBuffer index, FileChannel data) throws InsufficientSpace, IOException {
@@ -136,8 +150,8 @@
       return insert(new TrieLeaf(key, value), 0);
     }
 
-    public long lookup(byte[] key) throws NotFound {
-      return lookup(key, 0);
+    public long lookup(byte[] key, boolean[] valid) {
+      return lookup(key, 0, valid);
     }
 
     /**
@@ -151,7 +165,7 @@
     protected abstract int totalIndexSize();
     protected abstract int totalDataSize();
     protected abstract boolean insert(TrieLeaf node, int parentLcd);
-    protected abstract long lookup(byte[] key, int parentLcd) throws NotFound;
+    protected abstract long lookup(byte[] key, int parentLcd, boolean[] valid);
 
     protected static boolean regionMatches(byte[] lhs, int lhsOff, byte[] rhs, int rhsOff, int len) {
       if (lhsOff < 0 || rhsOff < 0) {
@@ -332,27 +346,31 @@
       }
     }
 
-    protected long lookup(byte[] key, int parentLcd) throws NotFound {
+    protected long lookup(byte[] key, int parentLcd, boolean[] valid) {
       if (!regionMatches(aLeaf.key, parentLcd, key, parentLcd, offset - parentLcd)) {
         //FIXME: I need to migrate this to the end of the search to avoid needing access to the key at each level.
-        throw new NotFound();
+        valid[0] = false;
+        return 0;
       } else {
         // new node matches the lcp of this node.
         TrieNode child;
         if (key.length == offset) {
           // new node is expected to terminate here.
           if (term != null) {
+            valid[0] = true;
             return term.value;
           } else {
-            throw new NotFound();
+            valid[0] = false;
+            return 0;
           }
         } else {
           // new node is expected to terminate in one of this nodes children.
           child = children.lookup(key[offset]);
           if (child != null) {
-            return child.lookup(key, offset);
+            return child.lookup(key, offset, valid);
           } else {
-            throw new NotFound();
+            valid[0] = false;
+            return 0;
           }
         }
       }
@@ -404,8 +422,9 @@
       }
     }
 
-    protected long lookup(byte[] key, int parentLcd) {
+    protected long lookup(byte[] key, int parentLcd, boolean[] valid) {
       assert Arrays.equals(this.key, key);
+      valid[0] = true;
       return value;
     }
     

Modified: projects/xa2/object-pool/src/MemoryTrieTest.java
===================================================================
--- projects/xa2/object-pool/src/MemoryTrieTest.java	2008-04-28 10:57:20 UTC (rev 860)
+++ projects/xa2/object-pool/src/MemoryTrieTest.java	2008-04-28 12:16:15 UTC (rev 861)
@@ -241,7 +241,7 @@
             nS++;
           }
 
-          for (int ii = 0; ii < 1000; ii++) {
+          for (int ii = 0; ii < 10; ii++) {
             key = new byte[((int)buffer.get()) & 0x0000001F];
             buffer.get(key);
             keyBytes = new Bytes(key);
@@ -252,7 +252,7 @@
               namesMap.put(keyBytes, n);
               long _sss = System.currentTimeMillis();
               namesTrie.insert(key, n);
-              _aggregateS += System.currentTimeMillis() - _sss;
+              _aggregateSS += System.currentTimeMillis() - _sss;
               _avlSS += key.length;
               nSS++;
             }




More information about the Mulgara-svn mailing list