From: Amaury Denoyelle Date: Wed, 22 Jul 2026 14:13:42 +0000 (+0200) Subject: OPTIM/MEDIUM: proxy: avoid main proxies list reordering on startup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=869163e10e4c66924a4b82d953aefed5f77031c0;p=thirdparty%2Fhaproxy.git OPTIM/MEDIUM: proxy: avoid main proxies list reordering on startup Prior to this patch, proxies were added in front ot the visible proxies list, resulting in the reverse order of their parsing. The list was then reversed once parsing was completed to reflect the configuration order. This was performed for performance reason, as visible proxies list was simply linked. This list has recently been converted to a doubly linked struct list. Thus, it is now possible to append a newly parsed proxy at the end of the list in constant time. Thus, with this patch, a newly parsed instance is now directly inserted at the end of main proxies list. This is implemented by updating main_proxies_register() wrapper. Post-config performance are slightly improved as reversal is now unneeded. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index a1720566f..9b6fa5b9e 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -314,13 +314,10 @@ static inline void increment_send_rate(uint64_t bytes, int splice) update_freq_ctr(&th_ctx->out_32bps, (bytes + 16) / 32); } -/* Insert at the front of the global list of visible proxies. This should - * only be used during configuration parsing. At runtime, a newly added proxy - * should be appended at the end of the list instead. - */ +/* Append at the end of the global list of visible proxies. */ static inline void main_proxies_register(struct proxy *px) { - LIST_INSERT(&main_proxies, &px->el); + LIST_APPEND(&main_proxies, &px->el); } /* Returns first entry in main proxies list or NULL if empty. */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 3a7a533fc..57d4bc54b 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2295,9 +2295,8 @@ static struct proxy *_get_next_proxy(void *head, struct proxy *cur) */ int check_config_validity() { - struct list tmp_list = LIST_HEAD_INIT(tmp_list); int cfgerr = 0, ret; - struct proxy *defpx, *old; + struct proxy *defpx; void *init_proxies_list = NULL; struct stktable *t; struct server *newsrv = NULL; @@ -2386,13 +2385,6 @@ int check_config_validity() if (err_code != ERR_NONE) goto out; - /* first, we will invert the proxy list order */ - list_for_each_entry_safe(curproxy, old, &main_proxies, el) { - LIST_DELETE(&curproxy->el); - LIST_INSERT(&tmp_list, &curproxy->el); - } - LIST_SPLICE(&main_proxies, &tmp_list); - /* * we must finish to initialize certain things on the servers, * as some of the fields may be accessed soon diff --git a/src/proxy.c b/src/proxy.c index eaab91f6f..af90dcbbf 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -4977,8 +4977,11 @@ static int cli_parse_add_backend(char **args, char *payload, struct appctx *appc proxy_index_id(px); dynpx_next_id = px->uuid; - LIST_APPEND(&main_proxies, &px->el); - + /* Insert into list of visible proxies. Note that + * insertion in has already been performed in + * setup_new_proxy() via alloc_new_proxy(). + */ + main_proxies_register(px); thread_release(); if (unlikely(!be_supports_dynamic_srv(px, &msg)))