From 52c6dd773d5e49d9506844e5cc14762933068564 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 17 Sep 2025 14:14:38 +0200 Subject: [PATCH] IMPORT: ebst: use prefetching in lookup() and insert() 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/import/ebsttree.h b/include/import/ebsttree.h index f4cee7078..590bec944 100644 --- a/include/import/ebsttree.h +++ b/include/import/ebsttree.h @@ -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