Skip to content

Commit

Permalink
Log Infini filter ram size during construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Sep 28, 2023
1 parent 40c0db4 commit a13f0c3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/org/peergos/blockstore/CidInfiniFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public static CidInfiniFilter build(Blockstore bs) {

public static CidInfiniFilter build(Blockstore bs, double falsePositiveRate) {
List<Cid> refs = bs.refs().join();
int nBlocks = refs.size();
int nBlocks = refs.size()*5/4; // increase by 25% to avoid expansion during build
int nextPowerOfTwo = Math.max(17, (int) (1 + Math.log(nBlocks) / Math.log(2)));
double expansionAlpha = 0.8;
int bitsPerEntry = (int)(4 - Math.log(falsePositiveRate / expansionAlpha) / Math.log(2) + 1);
System.out.println("Using infini filter of initial size " + ((double)(bitsPerEntry * (1 << nextPowerOfTwo) / 8) / 1024 / 1024) + " MiB");
ChainedInfiniFilter infini = new ChainedInfiniFilter(nextPowerOfTwo, bitsPerEntry);
infini.set_expand_autonomously(true);
refs.forEach(c -> infini.insert(c.toBytes(), true));
Expand Down

0 comments on commit a13f0c3

Please sign in to comment.