]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
IMPORT: ebst: use prefetching in lookup() and insert()
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Sep 2025 12:14:38 +0000 (14:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Sep 2025 12:30:32 +0000 (14:30 +0200)
While the previous optimizations couldn't be preserved due to the
possibility of out-of-bounds accesses, at least the prefetch is useful.
A test on treebench shows that for 64k short strings, the lookup time
falls from 276 to 199ns per lookup (28% savings), and the insert falls
from 311 to 296ns (4.9% savings), which are pretty respectable, so
let's do this.

This is ebtree commit b44ea5d07dc1594d62c3a902783ed1fb133f568d.

include/import/ebsttree.h

index f4cee7078e0e26e428a4bf75d4d3c767cedbc354..590bec944166f6bd1dbeb8d0694156cba91015ef 100644 (file)
@@ -75,6 +75,10 @@ static forceinline struct ebmb_node *__ebst_lookup(struct eb_root *root, const v
                }
                node = container_of(eb_untag(troot, EB_NODE),
                                    struct ebmb_node, node.branches);
+
+               eb_prefetch(node->node.branches.b[0], 0);
+               eb_prefetch(node->node.branches.b[1], 0);
+
                node_bit = node->node.bit;
 
                if (node_bit < 0) {
@@ -237,6 +241,10 @@ __ebst_insert(struct eb_root *root, struct ebmb_node *new)
                /* OK we're walking down this link */
                old = container_of(eb_untag(troot, EB_NODE),
                                   struct ebmb_node, node.branches);
+
+               eb_prefetch(old->node.branches.b[0], 0);
+               eb_prefetch(old->node.branches.b[1], 0);
+
                old_node_bit = old->node.bit;
 
                /* Stop going down when we don't have common bits anymore. We