]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: log: declare empty buffer as global variable
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 30 Apr 2024 14:45:34 +0000 (16:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 4 May 2024 08:13:05 +0000 (10:13 +0200)
'empty' buffer used in sess_build_logline() inside a loop, and since it
is only being read from and not modified, until recently it ended up being
cached most of the time and didn't cause overhead due to systematic push
on the stack.

However, due recent encoding work and new added variables on the stack,
we're starting to reach a stack limit and declaring 'empty' buffer within
the loop seems to cause non-negligible CPU overhead.

Since the variable isn't modified during log generation, let's declare
'empty' buffer as a global variable outside from sess_build_logline()
to prevent pushing it on the stack for each node evaluation.

src/log.c

index 14c03cc18d3bf66f8b0d5d2cbb3f64cf928d9d03..04417b08319445b26c463a2e6b99998db65c333c 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -119,6 +119,7 @@ const char *log_levels[NB_LOG_LEVELS] = {
 
 const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */
 const char sess_fin_state[8]  = "-RCHDLQT";    /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
+const struct buffer empty = { };
 
 
 int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy);
@@ -3642,7 +3643,6 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                const char *src = NULL;
                const char *value_beg = NULL;
                struct sample *key;
-               const struct buffer empty = { };
 
                /* first start with basic types (use continue statement to skip
                 * the current node)