From 684bd659ae0c6ca623422851c245188037658698 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Wed, 4 Nov 2015 19:18:12 +0000 Subject: [PATCH] Revert "Cache node IDs in a hash table for faster lookups." This reverts commit c2319e90b16962fe899bc60abc8af0e2542bb176. As a general principle, I do not believe it is worthwhile to cache nodes. Sure, it brings lookup time down from O(log n) to O(1), but considering that the scalability target of tinc is around 1000 nodes and log2(1000) is 10, that looks like premature optimization; tree lookups should already be very fast. Therefore, I believe it makes sense to remove the cache as a code cleanup initiative. --- src/node.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/node.c b/src/node.c index a571ae07..bd94ed0b 100644 --- a/src/node.c +++ b/src/node.c @@ -35,7 +35,6 @@ splay_tree_t *node_tree; static splay_tree_t *node_id_tree; static splay_tree_t *node_udp_tree; -static hash_t *node_id_cache; node_t *myself; @@ -58,11 +57,9 @@ void init_nodes(void) { node_tree = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node); node_id_tree = splay_alloc_tree((splay_compare_t) node_id_compare, NULL); node_udp_tree = splay_alloc_tree((splay_compare_t) node_udp_compare, NULL); - node_id_cache = hash_alloc(0x100, sizeof(node_id_t)); } void exit_nodes(void) { - hash_free(node_id_cache); splay_delete_tree(node_udp_tree); splay_delete_tree(node_id_tree); splay_delete_tree(node_tree); @@ -124,7 +121,6 @@ void node_add(node_t *n) { void node_del(node_t *n) { splay_delete(node_udp_tree, n); - hash_delete(node_id_cache, &n->id); for splay_each(subnet_t, s, n->subnet_tree) subnet_del(n, s); @@ -145,15 +141,8 @@ node_t *lookup_node(char *name) { } node_t *lookup_node_id(const node_id_t *id) { - node_t *n = hash_search(node_id_cache, id); - if(!n) { - node_t tmp = {.id = *id}; - n = splay_search(node_id_tree, &tmp); - if(n) - hash_insert(node_id_cache, id, n); - } - - return n; + node_t n = {.id = *id}; + return splay_search(node_id_tree, &n); } node_t *lookup_node_udp(const sockaddr_t *sa) { -- 2.20.1