]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Feature] Add inverted index for composites optimization
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 25 Nov 2025 17:13:19 +0000 (17:13 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 25 Nov 2025 17:13:19 +0000 (17:13 +0000)
commit6c19888b9b4bbceb29eb0b244a33d8a095751c60
tree8142d5c61a4a28391245a7911145164a69b24979
parente15327ef1f753429b576cb29a6b124f2f000113e
[Feature] Add inverted index for composites optimization

Build an inverted index mapping symbol names to composites that contain
those symbols as positive (non-negated) atoms. This allows filtering out
composites that cannot possibly match during the first pass evaluation.

- Add rspamd_expression_atom_foreach_ex() to traverse expression atoms
  with access to AST nodes (needed to detect negated atoms)
- Add rspamd_expression_node_is_op() to check if a node is an operator
- Build inverted index in composites_manager during config processing
- Track composites with only negated atoms separately (they must always
  be evaluated)
- Use inverted index in composites_metric_callback for first pass to
  evaluate only potentially matching composites

For configurations with many composites (4000+), this reduces the number
of composites evaluated per message from all to only those that have at
least one matching symbol present.
src/libserver/composites/composites.cxx
src/libserver/composites/composites_internal.hxx
src/libserver/composites/composites_manager.cxx
src/libutil/expression.c
src/libutil/expression.h