|
1 | 1 | Poptrie |
2 | 2 | ==== |
3 | | -A pure Rust implementation of [Poptrie](https://dl.acm.org/doi/10.1145/2740070.2626377), a data structure for efficient longest-prefix matching (LPM) lookups. |
| 3 | +A pure Rust implementation of [Poptrie](https://dl.acm.org/doi/abs/10.1145/2829988.2787474), a data structure for efficient longest-prefix matching (LPM) lookups. |
4 | 4 |
|
5 | 5 | Poptrie uses bitmaps combined with popcount to achieve fast IP routing table lookups with high cache locality. During lookup, the key is consumed in the biggest step that can be represented in a bitmap for which the native popcount instruction exists (i.e. 6-bit steps in a 64-bit bitmap). |
6 | 6 |
|
@@ -48,17 +48,30 @@ assert_eq!(trie.lookup(u32::from_be_bytes([192, 168, 1, 5])), Some(&"192.168.0.0 |
48 | 48 |
|
49 | 49 | | Function | Description | |
50 | 50 | |---|---| |
51 | | -| `Poptrie::new()` | Construct a new, empty poptrie | |
| 51 | +| `new()` | Construct a new, empty poptrie | |
52 | 52 | | `insert(key, key_length, value)` | Insert a value associated with the given prefix | |
53 | 53 | | `lookup(key)` | Longest-prefix match lookup, returns `Option<&V>` | |
54 | 54 | | `contains_key(key, key_length)` | Returns `true` if the exact prefix is present | |
55 | 55 | | `remove(key, key_length)` | Remove a prefix and return its value |### License |
56 | 56 |
|
57 | | -### Reference |
| 57 | +### Lookup performance |
| 58 | + |
| 59 | +Benchmarked with random lookups on tables of 1k, 10k and 100k random prefixes. All contenders were built with `RUSTFLAGS="-C target-cpu=native"`, which enables the use of architecture-specific instructions, if available. This is critical for performance as the poptrie relies on native `POPCNT` and bit manipulation instructions (e.g. `BEXTR` on x86) to achieve its performance characteristics. |
| 60 | + |
| 61 | +| Implementation | 1k prefixes | 10k prefixes | 100k prefixes | |
| 62 | +|---|---|---|---| |
| 63 | +| **nicolaskagami/poptrie** (this crate) | 462.9 Mlookups/s | 326.6 Mlookups/s | 171.1 Mlookups/s | |
| 64 | +| [tiborschneider/prefix-trie](https://github.com/tiborschneider/prefix-trie) | 296.9 Mlookups/s | 292.9 Mlookups/s | 110.5 Mlookups/s | |
| 65 | +| [oxidecomputer/poptrie](https://github.com/oxidecomputer/poptrie) | 270.1 Mlookups/s | 197.7 Mlookups/s | 86.9 Mlookups/s | |
| 66 | + |
| 67 | +> Benchmarked on an AMD Ryzen 9 7900 (12-core, x86_64), Linux kernel 6.18, rustc 1.93.1. |
58 | 68 |
|
59 | | -Hirochika Asai and Yasuhiro Ohara. 2015. **[Poptrie: A Compressed Trie with Population Count for Fast and Scalable Software IP Routing Table Lookup](https://doi.org/10.1145/2740070.2626377)**. In *Proceedings of the 2015 ACM Conference on Special Interest Group on Data Communication* (SIGCOMM '15). ACM, New York, NY, USA, 57–70. |
60 | 69 |
|
61 | 70 |
|
| 71 | +### Reference |
| 72 | + |
| 73 | +Asai, Hirochika, and Yasuhiro Ohara. "**[Poptrie: A Compressed Trie with Population Count for Fast and Scalable Software IP Routing Table Lookup](https://doi.org/10.1145/2829988.2787474)** ACM SIGCOMM Computer Communication Review 45.4 (2015): 57-70. |
| 74 | + |
62 | 75 | ### License |
63 | 76 |
|
64 | 77 | This project is licensed under either of: |
|
0 commit comments