]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: Optimization for dictionary cache lookup.
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 7 Jun 2019 12:25:25 +0000 (14:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Jun 2019 13:47:54 +0000 (15:47 +0200)
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.

include/types/peers.h
src/peers.c

index 1b260e46c240600d33de8928af3f0b66ec050669..1d9123d1d89da9c3cf01fbcb4da2c39748796a0e 100644 (file)
@@ -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;
 };
index 7cc817cbc1ea8a61ef436dc61908b97d74245bfc..10fee312c1efd529ee0da425411ace03daf71db8 100644 (file)
@@ -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;