]> git.kaiwu.me - haproxy.git/commitdiff
OPTIM: acl: only reset ctx and flags, not the whole sample
authorWilly Tarreau <w@1wt.eu>
Mon, 30 Nov 2026 18:56:25 +0000 (19:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2026 07:17:13 +0000 (08:17 +0100)
When evaluating an ACL, each expression starts with a memset(0) on the
local sample before calling sample_process(). This is a waste, as the
comment clearly says that the goal is to reset ctx and flags (i.e. 52
bytes), not the whole 144 (no need to erase a possibly older IPv6
address). Let's just do precisely that, because tests with many ACLs
show that up to 1.5% CPU is spent there with a few tens of rules, and
this memset() alone is responsible for 12-20% of the whole function's
time for short matches.

src/acl.c

index 806aab4cfc1c168e67ce0399f38ab907d1ac7a70..2e069d6316f26206b0d896a67b643fedcf213b81 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -1083,7 +1083,8 @@ enum acl_test_res acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct
                        acl_res = ACL_TEST_FAIL;
                        list_for_each_entry(expr, &acl->expr, list) {
                                /* we need to reset context and flags */
-                               memset(&smp, 0, sizeof(smp));
+                               memset(&smp.ctx, 0, sizeof(smp.ctx));
+                               smp.flags = smp.opt = 0;
                        fetch_next:
                                if (!sample_process(px, sess, strm, opt, expr->smp, &smp)) {
                                        /* maybe we could not fetch because of missing data */