Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

performance hacks to compare methods in database core

orbiter39644dc14eb0
diff --git a/source/de/anomic/kelondro/index/RowCollection.java b/source/de/anomic/kelondro/index/RowCollection.java
index c7572a866..fe7ff59bc 100644
--- a/source/de/anomic/kelondro/index/RowCollection.java
+++ b/source/de/anomic/kelondro/index/RowCollection.java
@@ -780,13 +780,13 @@ public class RowCollection implements Iterable<Row.Entry> {
boolean u = true;
try {
while (i >= 0) {
- if (compare(i, i + 1) == 0) {
+ if (match(i, i + 1)) {
removeRow(i + 1, false);
d++;
if (i + 1 < chunkcount - 1) u = false;
}
i--;
- if (System.currentTimeMillis() - t > 10000) {
+ if (System.currentTimeMillis() - t > 60000) {
throw new RuntimeException("uniq() time-out at " + i + " (backwards) from " + chunkcount + " elements after " + (System.currentTimeMillis() - t) + " milliseconds; " + d + " deletions so far");
}
}
@@ -811,7 +811,7 @@ public class RowCollection implements Iterable<Row.Entry> {
RowCollection collection = new RowCollection(this.rowdef, 2);
try {
while (i >= 0) {
- if (compare(i, i + 1) == 0) {
+ if (match(i, i + 1)) {
collection.addUnique(get(i + 1, false));
removeRow(i + 1, false);
d++;
@@ -919,13 +919,32 @@ public class RowCollection implements Iterable<Row.Entry> {
return rowdef.objectOrder.compare(a, astart, l, chunkcache, chunknumber * this.rowdef.objectsize + ((rowdef.primaryKeyIndex <= 0) ? 0 : this.rowdef.colstart[rowdef.primaryKeyIndex]), this.rowdef.primaryKeyLength);
}
- protected synchronized boolean match(final byte[] a, final int astart, final int alength, final int chunknumber) {
+ protected final boolean match(final int i, final int j) {
+ assert (chunkcount * this.rowdef.objectsize <= chunkcache.length) : "chunkcount = " + chunkcount + ", objsize = " + this.rowdef.objectsize + ", chunkcache.length = " + chunkcache.length;
+ assert (i >= 0) && (i < chunkcount) : "i = " + i + ", chunkcount = " + chunkcount;
+ assert (j >= 0) && (j < chunkcount) : "j = " + j + ", chunkcount = " + chunkcount;
+ if (i >= chunkcount) return false;
+ if (j >= chunkcount) return false;
+ assert (this.rowdef.objectOrder != null);
+ if (i == j) return true;
+ final int colstart = (this.rowdef.primaryKeyIndex <= 0) ? 0 : this.rowdef.colstart[this.rowdef.primaryKeyIndex];
+ int astart = i * this.rowdef.objectsize + colstart;
+ int bstart = j * this.rowdef.objectsize + colstart;
+ int k = this.rowdef.primaryKeyLength;
+ while (k-- != 0) {
+ if (chunkcache[astart++] != chunkcache[bstart++]) return false;
+ }
+ return true;
+ }
+
+ protected synchronized boolean match(final byte[] a, int astart, final int alength, final int chunknumber) {
if (chunknumber >= chunkcount) return false;
- int i = 0;
int p = chunknumber * this.rowdef.objectsize + ((rowdef.primaryKeyIndex <= 0) ? 0 : this.rowdef.colstart[rowdef.primaryKeyIndex]);
- final int len = Math.min(this.rowdef.primaryKeyLength, Math.min(alength, a.length - astart));
- while (i < len) if (a[astart + i++] != chunkcache[p++]) return false;
- return ((len == this.rowdef.primaryKeyLength) || (chunkcache[len] == 0)) ;
+ int len = Math.min(this.rowdef.primaryKeyLength, Math.min(alength, a.length - astart));
+ while (len-- != 0) {
+ if (a[astart++] != chunkcache[p++]) return false;
+ }
+ return true;
}
public synchronized void close() {
diff --git a/source/de/anomic/kelondro/index/RowSet.java b/source/de/anomic/kelondro/index/RowSet.java
index 2e9a3ed41..084a91721 100644
--- a/source/de/anomic/kelondro/index/RowSet.java
+++ b/source/de/anomic/kelondro/index/RowSet.java
@@ -202,7 +202,7 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
if (p >= 0) return p;
// then find in unsorted area
- return iterativeSearchCompiledPivot(compiledPivot, this.sortBound, this.chunkcount);
+ return iterativeSearch(a, astart, alength, this.sortBound, this.chunkcount);
} else {
// first try to find in sorted area
final int p = binarySearch(a, astart, alength);
@@ -215,25 +215,8 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
private int iterativeSearch(final byte[] key, final int astart, final int alength, final int leftBorder, final int rightBound) {
// returns the chunknumber
- if (rowdef.objectOrder == null) {
- for (int i = leftBorder; i < rightBound; i++) {
- if (match(key, astart, alength, i)) return i;
- }
- return -1;
- }
- // we dont do a special handling of kelondroBase64Order here, because tests showed that this produces too much overhead
- for (int i = leftBorder; i < rightBound; i++) {
- if (compare(key, astart, alength, i) == 0) return i;
- }
- return -1;
- }
-
- private int iterativeSearchCompiledPivot(final byte[] compiledPivot, final int leftBorder, final int rightBound) {
- // returns the chunknumber
- assert (rowdef.objectOrder != null);
- assert (rowdef.objectOrder instanceof Base64Order);
for (int i = leftBorder; i < rightBound; i++) {
- if (comparePivot(compiledPivot, i) == 0) return i;
+ if (match(key, astart, alength, i)) return i;
}
return -1;
}