]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Optimize] Add rspamd_heap_push_slot to eliminate double allocation
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 21 Oct 2025 10:34:58 +0000 (11:34 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 21 Oct 2025 10:34:58 +0000 (11:34 +0100)
commit962c4ef589abce40adaf8835a1b9c89bfc3caa98
treee6d0ec286d75e02a3ba3df69893a18c34be0860e
parent9416ae7f2920d8dece1366572a7c0e494ff9ba70
[Optimize] Add rspamd_heap_push_slot to eliminate double allocation

Add rspamd_heap_push_slot() macro that allocates a slot directly in
the heap and returns a pointer to it, avoiding unnecessary copying.

Previously, memory pool destructors were allocated twice:
1. First allocated in mempool via rspamd_mempool_alloc_
2. Then copied into heap via rspamd_heap_push_safe

New approach:
- rspamd_heap_push_slot allocates zero-initialized slot in heap
- Returns pointer to the slot for direct filling
- User calls rspamd_heap_swim after filling to restore heap property

Benefits:
- Eliminates duplicate allocation of destructor structures
- Reduces memory usage (no temporary allocation in mempool)
- Better cache locality (destructor lives only in heap)
- Same pattern can be used elsewhere for efficient heap usage

Updated rspamd_mempool_add_destructor_full to use new API.
src/libutil/heap.h
src/libutil/mem_pool.c