|
1 | 1 | # fastfilter_cpp |
| 2 | + |
2 | 3 | Fast Filter: Fast approximate membership filter implementations (C++) |
3 | 4 |
|
4 | | -This is a research library, developers might want to consider our [Header-only Xor Filter library in C](https://github.com/FastFilter/xor_singleheader/). |
| 5 | +This is a research library currently. It is not meant for production use. |
| 6 | + |
| 7 | +Developers might want to consider our [Header-only Xor Filter library in C](https://github.com/FastFilter/xor_singleheader/). |
| 8 | + |
| 9 | +Reference: [Xor Filters: Faster and Smaller Than Bloom and Cuckoo Filters](https://arxiv.org/abs/1912.08258), Journal of Experimental Algorithmics (to appear). |
| 10 | + |
| 11 | + |
5 | 12 |
|
6 | 13 | ## Prerequisites |
7 | 14 |
|
8 | 15 | - A C++11 compiler such as GNU G++ or LLVM Clang++ |
9 | | -- Make |
| 16 | +- Make |
10 | 17 |
|
| 18 | +Expectations: |
11 | 19 |
|
| 20 | +- Though it should be possible to run this benchmark on any operating system, we expect Linux and use its performance counters to measure performance. |
| 21 | +- We expect an x64 processor with AVX2 support though most filters work on any processor, if you compile on a machine that does not support AVX2 instructions, the corresponding filters that depend on AVX2 will be disabled. |
12 | 22 |
|
13 | 23 | ## Usage |
14 | 24 |
|
| 25 | +Make sure to select the right GNU GCC compiler (e.g., via `export export CXX=g++-8`). |
| 26 | +You may want to disable hyperthreading and adjust page sizes. Run the benchmark |
| 27 | +on a quiet machine. |
| 28 | + |
| 29 | + |
15 | 30 | ``` |
| 31 | +git clone https://github.com/FastFilter/fastfilter_cpp.git |
| 32 | +cd fastfilter_cpp |
16 | 33 | cd benchmarks |
17 | 34 | make |
| 35 | +# there may be compiler warnings at this point, we compile with '-Wall' |
18 | 36 | ./bulk-insert-and-query.exe 10000000 |
| 37 | +# collect the output (it is quite verbose) |
| 38 | +./bulk-insert-and-query.exe 100000000 |
| 39 | +``` |
| 40 | + |
| 41 | +Your results will depend on the hardware, on the compiler and how the system is configured. A sample output is as follows: |
| 42 | + |
| 43 | +``` |
| 44 | +$ ./bulk-insert-and-query.exe 10000000 |
| 45 | + find find find find find optimal wasted million |
| 46 | + add remove 0% 25% 50% 75% 100% ε bits/item bits/item space keys |
| 47 | +
|
| 48 | +add cycles: 325.5/key, instructions: (303.2/key, 0.93/cycle) cache misses: 12.41/key branch misses: 1.17/key |
| 49 | +0.00% cycles: 81.7/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key |
| 50 | +0.25% cycles: 81.8/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key |
| 51 | +0.50% cycles: 81.8/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key |
| 52 | +0.75% cycles: 82.0/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key |
| 53 | +1.00% cycles: 81.9/key, instructions: ( 48.0/key, 0.59/cycle) cache misses: 3.06/key branch misses: 0.00/key |
| 54 | + Xor8 106.79 0.00 25.92 25.88 25.86 25.94 25.98 0.3892% 9.84 8.01 22.9% 10.0 |
| 55 | +
|
| 56 | +... # many more lines omitted |
19 | 57 | ``` |
20 | 58 |
|
| 59 | +The `add` lines preceding the name of each algorithm gives you information regarding the construction time whereas |
| 60 | +the other five lines give you information regarding the queries where a given percentage of elements are present |
| 61 | +in the set. We use Linux performance counters to measure instructions, cache misses and branch misses. |
| 62 | + |
| 63 | +As part of the benchmark, we check the correctness of the implementation. |
| 64 | + |
| 65 | +## Benchmarking |
| 66 | + |
| 67 | +The shell script `benchmark/benchmark.sh` runs the benchmark 3 times for the most important algorithms, |
| 68 | +with entry sizes of 10 million and 100 million keys. |
| 69 | +It is much slower than the above, because each invocation runs only one algorithm |
| 70 | +(to ensure running one algorithm doesn't influence benchmark results of other algorithms). |
| 71 | +It stores the results in the file `benchmark-results.txt`. |
| 72 | +To futher analyze the results, use the java tool `AnalyzeResults.java` |
| 73 | +from the project https://github.com/FastFilter/fastfilter_java. |
| 74 | +Requires GCC and Java 8. |
| 75 | +To get a low error, it is best run on a Linux machine that is not otherwise in use. |
| 76 | +Steps to run the tests and analyze the results: |
| 77 | + |
| 78 | + git clone https://github.com/FastFilter/fastfilter_cpp.git |
| 79 | + git clone https://github.com/FastFilter/fastfilter_java.git |
| 80 | + cd fastfilter_cpp/benchmarks |
| 81 | + make clean ; make |
| 82 | + # this may take an hour to run |
| 83 | + ./benchmark.sh |
| 84 | + |
| 85 | + cd ../.. |
| 86 | + cd fastfilter_java |
| 87 | + mvn clean install |
| 88 | + java -cp target/test-classes org.fastfilter.analysis.AnalyzeResults ../fastfilter_cpp/benchmarks/benchmark-results.txt |
| 89 | + |
21 | 90 |
|
22 | 91 | ## Where is your code? |
23 | 92 |
|
24 | | -The filter implementations are in `src`, most are single header files and depend on `src/hashutil.h`: |
| 93 | +The filter implementations are in `src/<type>/`. Most implementations depend on `src/hashutil.h`. Examples: |
25 | 94 |
|
26 | | -* src/bloom.h |
27 | | -* src/xorfilter.h |
| 95 | +* src/bloom/bloom.h |
| 96 | +* src/xorfilter/xorfilter.h |
28 | 97 |
|
29 | 98 | ## Credit |
30 | 99 |
|
31 | 100 | The cuckoo filter and the benchmark are derived from https://github.com/efficient/cuckoofilter by Bin Fan et al. |
| 101 | +The SIMD blocked Bloom filter is from https://github.com/apache/impala (via the cuckoo filter). |
| 102 | +The Morton filter is from https://github.com/AMDComputeLibraries/morton_filter. |
| 103 | +The Counting Quotient Filter (CQF) is from https://github.com/splatlab/cqf. |
| 104 | + |
| 105 | + |
| 106 | +# Implementations of xor filters in other programming languages |
| 107 | + |
| 108 | +* [Go](https://github.com/FastFilter/xorfilter) |
| 109 | +* [Erlang](https://github.com/mpope9/exor_filter) |
| 110 | +* Rust: [1](https://github.com/bnclabs/xorfilter), [2](https://github.com/codri/xorfilter-rs), [3](https://github.com/Polochon-street/rustxorfilter) |
| 111 | +* [Java](https://github.com/FastFilter/fastfilter_java) |
| 112 | +* [C](https://github.com/FastFilter/xor_singleheader) |
| 113 | +* [Python](https://github.com/GreyDireWolf/pyxorfilter) |
0 commit comments