From: Frédéric Lécaille Date: Fri, 7 Jun 2019 12:25:25 +0000 (+0200) Subject: MINOR: peers: Optimization for dictionary cache lookup. X-Git-Tag: v2.0-dev7~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b65717fa55fe01e9972e7c809c775d948922a03c;p=thirdparty%2Fhaproxy.git MINOR: peers: Optimization for dictionary cache lookup. When we look up an dictionary entry in the cache used upon transmission we store the last result in ->prev_lookup of struct dcache_tx so that to compare it with the subsequent entries to look up and save performances. --- diff --git a/include/types/peers.h b/include/types/peers.h index 1b260e46c2..1d9123d1d8 100644 --- a/include/types/peers.h +++ b/include/types/peers.h @@ -102,6 +102,8 @@ struct dcache_tx { unsigned int lru_key; /* An array of entries to store pointers to dictionary entries. */ struct ebpt_node *entries; + /* The previous lookup result. */ + struct ebpt_node *prev_lookup; /* ebtree to store the previous entries. */ struct eb_root cached_entries; }; diff --git a/src/peers.c b/src/peers.c index 7cc817cbc1..10fee312c1 100644 --- a/src/peers.c +++ b/src/peers.c @@ -2849,6 +2849,7 @@ static struct dcache_tx *new_dcache_tx(size_t max_entries) goto err; d->lru_key = 0; + d->prev_lookup = NULL; d->cached_entries = EB_ROOT_UNIQUE; d->entries = entries; @@ -2948,7 +2949,17 @@ static struct ebpt_node *dcache_tx_insert(struct dcache *dc, struct dcache_tx_en struct ebpt_node *o; dc_tx = dc->tx; - o = dcache_tx_lookup_value(dc_tx, i); + + if (dc_tx->prev_lookup && dc_tx->prev_lookup->key == i->entry.key) { + o = dc_tx->prev_lookup; + } else { + o = dcache_tx_lookup_value(dc_tx, i); + if (o) { + /* Save it */ + dc_tx->prev_lookup = o; + } + } + if (o) { /* Copy the ID. */ i->id = o - dc->tx->entries; @@ -2956,7 +2967,7 @@ static struct ebpt_node *dcache_tx_insert(struct dcache *dc, struct dcache_tx_en } /* The new entry to put in cache */ - o = &dc_tx->entries[dc_tx->lru_key]; + dc_tx->prev_lookup = o = &dc_tx->entries[dc_tx->lru_key]; ebpt_delete(o); o->key = i->entry.key;