Skip to content

Commit 555994c

Browse files
committed
OPTIM: pattern: only apply LRU cache for large enough lists
As shown in issue #1518, the LRU cache has a non-null cost that can sometimes be above the match cost it's trying to avoid. After a number of tests, it appears that: - "simple" match operations (sub, beg, end, int etc) reach a break-even after ~20 patterns in list - "heavy" match operations (reg) reach a break-even after ~5 patterns in list Let's only consult the LRU cache when the number of patterns in the expression is at least as large as this limit. Of course there will always be outliers but it already starts good. Another improvement consists in reducing the cache size to further speed up lookups, which makes sense if less expressions use the cache.
1 parent 25b0592 commit 555994c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/pattern.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int
496496
}
497497

498498
/* look in the list */
499-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
499+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
500500
unsigned long long seed = pat_lru_seed ^ (long)expr;
501501

502502
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@@ -539,7 +539,7 @@ struct pattern *pat_match_bin(struct sample *smp, struct pattern_expr *expr, int
539539
struct pattern *ret = NULL;
540540
struct lru64 *lru = NULL;
541541

542-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
542+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
543543
unsigned long long seed = pat_lru_seed ^ (long)expr;
544544

545545
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@@ -608,7 +608,7 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int
608608
struct pattern *ret = NULL;
609609
struct lru64 *lru = NULL;
610610

611-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
611+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 5) {
612612
unsigned long long seed = pat_lru_seed ^ (long)expr;
613613

614614
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@@ -674,7 +674,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int
674674
}
675675

676676
/* look in the list */
677-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
677+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
678678
unsigned long long seed = pat_lru_seed ^ (long)expr;
679679

680680
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@@ -718,7 +718,7 @@ struct pattern *pat_match_end(struct sample *smp, struct pattern_expr *expr, int
718718
struct pattern *ret = NULL;
719719
struct lru64 *lru = NULL;
720720

721-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
721+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
722722
unsigned long long seed = pat_lru_seed ^ (long)expr;
723723

724724
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@@ -766,7 +766,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int
766766
struct pattern *ret = NULL;
767767
struct lru64 *lru = NULL;
768768

769-
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
769+
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
770770
unsigned long long seed = pat_lru_seed ^ (long)expr;
771771

772772
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),

0 commit comments

Comments
 (0)