diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-07-24 19:48:28 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-07-24 19:48:28 +0100 |
commit | 65daeed69c7cf8e8b95935a1d1c91fe086caea9e (patch) | |
tree | 360c24a1ad9dde084625f98d679bce2b49ca2cea /src/libmime | |
parent | 558bae256922e3c4149fd9798dbd98b04bd5cc55 (diff) | |
download | rspamd-65daeed69c7cf8e8b95935a1d1c91fe086caea9e.tar.gz rspamd-65daeed69c7cf8e8b95935a1d1c91fe086caea9e.zip |
[Minor] Preallocate results hash tables
Diffstat (limited to 'src/libmime')
-rw-r--r-- | src/libmime/filter.c | 15 |
1 files changed, 15 insertions, 0 deletions
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 <math.h> #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; } |