Skip to content

Commit

Permalink
MINOR: vars: remove the emptiness tests in callers before pruning
Browse files Browse the repository at this point in the history
All callers of vars_prune_* currently check the list for emptiness.
Let's leave that to vars_prune() itself, it will ease some changes in
the code. Thanks to the previous inlining of the vars_prune() function,
there's no performance loss, and even a very tiny 0.1% gain.
  • Loading branch information
wtarreau committed Sep 15, 2024
1 parent 2c1a9c3 commit 6e92988
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions include/haproxy/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ static inline void vars_prune(struct vars *vars, struct session *sess, struct st
size += var_clear(var, 1);
}

if (!size)
return;

var_accounting_diff(vars, sess, strm, -size);
}

Expand Down
9 changes: 3 additions & 6 deletions src/http_ana.c
Original file line number Diff line number Diff line change
Expand Up @@ -2967,8 +2967,7 @@ int http_eval_after_res_rules(struct stream *s)

/* prune the request variables if not already done and swap to the response variables. */
if (s->vars_reqres.scope != SCOPE_RES) {
if (!LIST_ISEMPTY(&s->vars_reqres.head))
vars_prune(&s->vars_reqres, s->sess, s);
vars_prune(&s->vars_reqres, s->sess, s);
vars_init_head(&s->vars_reqres, SCOPE_RES);
}

Expand Down Expand Up @@ -5094,10 +5093,8 @@ void http_destroy_txn(struct stream *s)
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;

if (!LIST_ISEMPTY(&s->vars_txn.head))
vars_prune(&s->vars_txn, s->sess, s);
if (!LIST_ISEMPTY(&s->vars_reqres.head))
vars_prune(&s->vars_reqres, s->sess, s);
vars_prune(&s->vars_txn, s->sess, s);
vars_prune(&s->vars_reqres, s->sess, s);

b_free(&txn->l7_buffer);

Expand Down
9 changes: 3 additions & 6 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,8 @@ void stream_free(struct stream *s)
}

/* Cleanup all variable contexts. */
if (!LIST_ISEMPTY(&s->vars_txn.head))
vars_prune(&s->vars_txn, s->sess, s);
if (!LIST_ISEMPTY(&s->vars_reqres.head))
vars_prune(&s->vars_reqres, s->sess, s);
vars_prune(&s->vars_txn, s->sess, s);
vars_prune(&s->vars_reqres, s->sess, s);

stream_store_counters(s);
pool_free(pool_head_stk_ctr, s->stkctr);
Expand Down Expand Up @@ -2309,8 +2307,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
if (sc_state_in(scb->state, SC_SB_REQ|SC_SB_QUE|SC_SB_TAR|SC_SB_ASS)) {
/* prune the request variables and swap to the response variables. */
if (s->vars_reqres.scope != SCOPE_RES) {
if (!LIST_ISEMPTY(&s->vars_reqres.head))
vars_prune(&s->vars_reqres, s->sess, s);
vars_prune(&s->vars_reqres, s->sess, s);
vars_init_head(&s->vars_reqres, SCOPE_RES);
}

Expand Down
3 changes: 3 additions & 0 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ void vars_prune_per_sess(struct vars *vars)
size += var_clear(var, 1);
}

if (!size)
return;

if (var_sess_limit)
_HA_ATOMIC_SUB(&vars->size, size);
if (var_proc_limit || var_global_limit)
Expand Down

0 comments on commit 6e92988

Please sign in to comment.