From: Vsevolod Stakhov Date: Tue, 6 Jan 2026 12:47:20 +0000 (+0000) Subject: [Minor] Skip ACISM fallback build when file cache hit X-Git-Tag: 4.0.0~208^2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e95f052f3fa0deda0ddddd2afa145840fe935ead;p=thirdparty%2Frspamd.git [Minor] Skip ACISM fallback build when file cache hit In FALLBACK mode, try loading from file cache first. If successful, skip building the ACISM trie to save memory. ACISM is only built on cache miss (when async compilation is needed). --- diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c index 256641fd37..9795b9c45a 100644 --- a/src/libutil/multipattern.c +++ b/src/libutil/multipattern.c @@ -738,9 +738,26 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** rspamd_cryptobox_hash_update(&mp->hash_state, (void *) &plt, sizeof(plt)); rspamd_cryptobox_hash_final(&mp->hash_state, hash); - /* FALLBACK mode: build ACISM first for immediate use */ + /* FALLBACK mode: try file cache first, build ACISM only on cache miss */ if (mp->mode == RSPAMD_MP_MODE_FALLBACK && has_acism_patterns) { - /* Build temporary ac_trie_pat_t array for acism_create */ + /* Try to load from file cache first - if hit, skip ACISM building */ + if (!(flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS) && + rspamd_multipattern_try_load_hs(mp, hash)) { + if (!rspamd_multipattern_alloc_scratch(mp, err)) { + rspamd_hyperscan_free(mp->hs_db, true); + mp->hs_db = NULL; + g_clear_error(err); + /* Fall through to build ACISM */ + } + else { + mp->state = RSPAMD_MP_STATE_COMPILED; + mp->compiled = TRUE; + msg_debug_multipattern("loaded hyperscan from cache, skipping ACISM build"); + return TRUE; + } + } + + /* Cache miss or scratch failed - build ACISM for fallback */ ac_trie_pat_t *tmp_pats = g_new(ac_trie_pat_t, mp->pats->len); for (unsigned int i = 0; i < mp->pats->len; i++) { struct rspamd_acism_pat *ap = &g_array_index(mp->pats, @@ -755,23 +772,7 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError ** msg_debug_multipattern("built ACISM fallback trie for %ud patterns", mp->pats->len); - /* Try to load from cache */ - if (!(flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS) && - rspamd_multipattern_try_load_hs(mp, hash)) { - if (!rspamd_multipattern_alloc_scratch(mp, err)) { - rspamd_hyperscan_free(mp->hs_db, true); - mp->hs_db = NULL; - mp->state = RSPAMD_MP_STATE_FALLBACK; - g_clear_error(err); - } - else { - mp->state = RSPAMD_MP_STATE_COMPILED; - msg_debug_multipattern("loaded hyperscan from cache"); - } - return TRUE; - } - - /* Cache miss - mark for async compilation */ + /* Mark for async compilation (hs_helper will compile and notify) */ if (!(flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS)) { mp->state = RSPAMD_MP_STATE_COMPILING; msg_debug_multipattern("cache miss, queued for async compile");