From: Aurelien DARRAGON Date: Tue, 30 Apr 2024 14:45:34 +0000 (+0200) Subject: OPTIM: log: declare empty buffer as global variable X-Git-Tag: v3.0-dev10~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=728b5aa835b40278f96a4330369bd6316fe51832;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/log.c b/src/log.c index 14c03cc18d..04417b0831 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)