From: Willy Tarreau Date: Tue, 22 Aug 2023 05:22:05 +0000 (+0200) Subject: MINOR: pattern: do not needlessly lookup the LRU cache for empty lists X-Git-Tag: v2.9-dev4~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=821fc95146ca9bc79f0e890d8c648203c2756583;p=thirdparty%2Fhaproxy.git MINOR: pattern: do not needlessly lookup the LRU cache for empty lists If a pattern list is empty, there's no way we can find its elements in the pattern cache, so let's avoid this expensive lookup. This can happen for ACLs or maps loaded from files that may optionally be empty for example. Doing so improves the request rate by roughly 10% for a single such match for only 8 threads. That's normal because the LRU cache pre-creates an entry that is about to be committed for the case the list lookup succeeds after a miss, so we bypass all this. --- diff --git a/src/pattern.c b/src/pattern.c index 6c263bebec..ce0f07b40a 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -491,7 +491,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int } /* look in the list */ - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed), @@ -534,7 +534,7 @@ struct pattern *pat_match_bin(struct sample *smp, struct pattern_expr *expr, int struct pattern *ret = NULL; struct lru64 *lru = NULL; - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed), @@ -603,7 +603,7 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int struct pattern *ret = NULL; struct lru64 *lru = NULL; - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed), @@ -686,7 +686,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int } /* look in the list */ - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed), @@ -730,7 +730,7 @@ struct pattern *pat_match_end(struct sample *smp, struct pattern_expr *expr, int struct pattern *ret = NULL; struct lru64 *lru = NULL; - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed), @@ -778,7 +778,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int struct pattern *ret = NULL; struct lru64 *lru = NULL; - if (pat_lru_tree) { + if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) { unsigned long long seed = pat_lru_seed ^ (long)expr; lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),