From: Vsevolod Stakhov Date: Tue, 24 Jul 2018 18:48:28 +0000 (+0100) Subject: [Minor] Preallocate results hash tables X-Git-Tag: 1.7.9~48 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=65daeed69c7cf8e8b95935a1d1c91fe086caea9e;p=rspamd.git [Minor] Preallocate results hash tables --- diff --git a/src/libmime/filter.c b/src/libmime/filter.c index e4862b0fd..1c836e4a7 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -22,12 +22,17 @@ #include #include "contrib/uthash/utlist.h" +/* Average symbols count to optimize hash allocation */ +static struct rspamd_counter_data symbols_count; + static void rspamd_metric_result_dtor (gpointer d) { struct rspamd_metric_result *r = (struct rspamd_metric_result *)d; struct rspamd_symbol_result sres; + rspamd_set_counter_ema (&symbols_count, kh_size (r->symbols), 0.5); + kh_foreach_value (r->symbols, sres, { if (sres.options) { kh_destroy (rspamd_options_hash, sres.options); @@ -56,6 +61,16 @@ rspamd_create_metric_result (struct rspamd_task *task) metric_res->grow_factor = 0; metric_res->score = 0; + /* Optimize allocation */ + kh_resize (rspamd_symbols_group_hash, metric_res->sym_groups, 4); + + if (symbols_count.mean > 4) { + kh_resize (rspamd_symbols_hash, metric_res->symbols, symbols_count.mean); + } + else { + kh_resize (rspamd_symbols_hash, metric_res->symbols, 4); + } + for (i = 0; i < METRIC_ACTION_MAX; i++) { metric_res->actions_limits[i] = task->cfg->actions[i].score; }