Add compile-time inline ownership hook (ALLOC8_XXOWNS_INLINE_HEADER)#9
Merged
Conversation
The runtime xxowns() hook always costs one function call per
free/realloc/malloc_size: the weak module-local default definition
blocks cross-module inlining under (Thin)LTO, so even an allocator
that provides a two-load ownership predicate pays call overhead on
every operation. Profiling Hoard on larson showed the wrapper layer
(entry checks + the xxowns call) at roughly 25-30% of total cycles.
Since the macOS interpose sources are compiled inside the consumer's
target, a compile-time hook can do better: the consumer defines
ALLOC8_XXOWNS_INLINE_HEADER (directly or via the new CMake cache
variable) naming a header that provides
static inline bool alloc8_xxowns_inline(const void* p);
with the same contract as xxowns() (safe on any address, no false
positives or negatives). The predicate then inlines straight into
replace_free / replace_realloc / replace_malloc_size, the runtime
"do we have a hook?" branch disappears, and per-allocation
track/untrack bookkeeping compiles away entirely.
Measured with Hoard on an M1 Max (8 threads), runtime hook -> inline
hook: larson 185M -> 211M ops/s (+14%), threadtest 0.85s -> 0.66s
(-23%), linux-scalability 0.127s -> 0.093s (-27%).
The runtime xxowns() path and the internal size table are unchanged
for allocators that do not opt in.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a third, fastest ownership-dispatch mode to the macOS wrapper: a compile-time inline hook. The consumer defines
ALLOC8_XXOWNS_INLINE_HEADER(directly or via the new CMake cache variable) naming a header that provides:with the same contract as
xxowns()— safe on any address, no false positives or negatives.Why
The runtime
xxowns()hook always costs one function call per free/realloc/malloc_size: the weak module-local default definition blocks cross-module inlining under (Thin)LTO, so even a two-load ownership predicate pays call overhead on every operation. Profiling Hoard on larson showed the wrapper layer (entry checks + thexxownscall) at ~25–30% of total cycles.Because the interpose sources are compiled inside the consumer's target, a compile-time hook inlines straight into
replace_free/replace_realloc/replace_malloc_size; the runtime "do we have a hook?" branch disappears and per-allocation track/untrack bookkeeping compiles away entirely. After this change,replace_free's owned-pointer path contains zero calls.Results (Hoard on M1 Max, 8 threads, runtime hook → inline hook)
Compatibility
xxowns()and the internal size table are unchanged).hoardownsinline.h.Testing
blon the owned-free path).🤖 Generated with Claude Code