From 728b5aa835b40278f96a4330369bd6316fe51832 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 30 Apr 2024 16:45:34 +0200 Subject: [PATCH] OPTIM: log: declare empty buffer as global variable '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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index 14c03cc18..04417b083 100644 --- 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)