Skip to content

Commit

Permalink
Performance: optimize ArrayHitCounter increment method (benchmarks im…
Browse files Browse the repository at this point in the history
…proved by up to 10%) (#609)
  • Loading branch information
alexklibisz authored Nov 29, 2023
1 parent 4208fa6 commit 8d02b6d
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 793 deletions.
1,592 changes: 820 additions & 772 deletions docs/pages/performance/fashion-mnist/plot.b64

Large diffs are not rendered by default.

Binary file modified docs/pages/performance/fashion-mnist/plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions docs/pages/performance/fashion-mnist/results.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
|Model|Parameters|Recall|Queries per Second|
|---|---|---|---|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=500 probes=0|0.378|349.604|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=1000 probes=0|0.446|288.333|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=500 probes=3|0.634|269.480|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=1000 probes=3|0.716|235.347|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=500 probes=0|0.768|274.087|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=1000 probes=0|0.846|234.908|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=500 probes=3|0.922|182.956|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=1000 probes=3|0.960|166.097|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=500 probes=0|0.378|346.083|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=1000 probes=0|0.446|289.601|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=500 probes=3|0.634|276.494|
|eknn-l2lsh|L=100 k=4 w=1024 candidates=1000 probes=3|0.716|242.322|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=500 probes=0|0.767|301.259|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=1000 probes=0|0.847|259.373|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=500 probes=3|0.922|201.386|
|eknn-l2lsh|L=100 k=4 w=2048 candidates=1000 probes=3|0.960|180.637|
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ public ArrayHitCounter(int capacity) {

@Override
public void increment(int key, short count) {
if (counts[key] == 0) {
if ((counts[key] += count) == count) {
numHits++;
minKey = Math.min(key, minKey);
maxKey = Math.max(key, maxKey);
}
counts[key] += count; // Important to be after the above.
}

@Override
public void increment(int key, int count) {
increment(key, (short) count);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ public final class EmptyHitCounter implements HitCounter {
@Override
public void increment(int key, short count) {}

@Override
public void increment(int key, int count) {}

@Override
public boolean isEmpty() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface HitCounter {

void increment(int key, short count);

void increment(int key, int count);

boolean isEmpty();

short get(int key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private HitCounter countHits(LeafReader reader) throws IOException {
if (termsEnum.seekExact(new BytesRef(hf.hash))) {
docs = termsEnum.postings(docs, PostingsEnum.NONE);
while (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
counter.increment(docs.docID(), min(hf.freq, docs.freq()));
counter.increment(docs.docID(), (short) min(hf.freq, docs.freq()));
}
}
}
Expand Down

0 comments on commit 8d02b6d

Please sign in to comment.