]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: do not needlessly lookup the LRU cache for empty lists
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Aug 2023 05:22:05 +0000 (07:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Aug 2023 05:27:01 +0000 (07:27 +0200)
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.

src/pattern.c

index 6c263bebecadbe948d76da61e172214c08331477..ce0f07b40a968973510fc9789a11eef802fe11a7 100644 (file)
@@ -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),