From 91d31c9e1c34eb760b8d1bd8e2e79ccf48096884 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 15 Nov 2022 08:08:31 +0100 Subject: [PATCH] OPTIM: ebtree: make ebmb_insert_prefix() keep a copy the new node's key Similarly to the previous patch, it's better to keep a local copy of the new node's key instead of accessing it every time. This slightly reduces the code's size in the descent and further improves the load time to 7.45s. --- include/import/ebmbtree.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/import/ebmbtree.h b/include/import/ebmbtree.h index fc6a5002e..365042e16 100644 --- a/include/import/ebmbtree.h +++ b/include/import/ebmbtree.h @@ -620,6 +620,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l int old_node_bit; unsigned int npfx = new->node.pfx; unsigned int npfx1 = npfx << 1; + const unsigned char *nkey = new->key; side = EB_LEFT; troot = root->b[EB_LEFT]; @@ -679,13 +680,13 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l /* No need to compare everything if the leaves are shorter than the new one. */ if (len > old->node.pfx) len = old->node.pfx; - bit = equal_bits(new->key, old->key, bit, len); + bit = equal_bits(nkey, old->key, bit, len); break; } /* WARNING: for the two blocks below, is counted in half-bits */ - bit = equal_bits(new->key, old->key, bit, old_node_bit >> 1); + bit = equal_bits(nkey, old->key, bit, old_node_bit >> 1); bit = (bit << 1) + 1; // assume comparisons with normal nodes /* we must always check that our prefix is larger than the nodes @@ -710,7 +711,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l new->node.node_p = old->node.node_p; up_ptr = &old->node.node_p; new->node.bit = bit; - diff = cmp_bits(new->key, old->key, bit >> 1); + diff = cmp_bits(nkey, old->key, bit >> 1); goto insert_above; } @@ -746,7 +747,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l root = &old->node.branches; side = old_node_bit & 7; side ^= 7; - side = (new->key[old_node_bit >> 3] >> side) & 1; + side = (nkey[old_node_bit >> 3] >> side) & 1; troot = root->b[side]; } @@ -789,7 +790,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l */ diff = 0; if (bit < old->node.pfx && bit < npfx) - diff = cmp_bits(new->key, old->key, bit); + diff = cmp_bits(nkey, old->key, bit); if (diff == 0) { /* Both keys match. Either it's a duplicate entry or we have to