feat(malloc_utils): add mimalloc and tcmalloc allocator feature flags#8884
feat(malloc_utils): add mimalloc and tcmalloc allocator feature flags#88840xMars42 wants to merge 4 commits intosigp:unstablefrom
Conversation
Add feature flags for mimalloc and tcmalloc as alternatives to jemalloc, which has been deprecated upstream. Both allocators override jemalloc via cfg guards, matching the existing sysmalloc override pattern. Allocator metrics are stubbed for now and can be fleshed out in a follow-up once a preferred allocator is chosen. Usage: cargo build -p lighthouse --features mimalloc cargo build -p lighthouse --features tcmalloc Closes sigp#8840
962bbcd to
c8da760
Compare
|
Please familiarise yourself with our policy regarding AI contributions (currently in review but likely to be merged very soon): |
michaelsproul
left a comment
There was a problem hiding this comment.
Looks like a good starting point.
I think there are probably a few more considerations to help us choose between tcmalloc and mimalloc, like:
- Node performance: we should deploy some long-running nodes with both allocators and observe their performance
- Debug tooling: which allocator has better tools for debugging, e.g. live allocation counts, heap introspection, etc.
- Compile time: does one of the two compile substantially faster?
|
Interesting that modern tcmalloc doesn't support macOS. That might be a reason to go deeper on mimalloc. It could also be that the macOS system allocator is fine for Lighthouse. It's mostly the glibc allocator we want to avoid. |
Thanks for the great feedback! Don't hesitate if you'd like me to adjust anything else. |
Closes #8840
Adds
mimallocandtcmallocfeature flags tomalloc_utils,lighthouse, andlclicrates.Usage
mimalloc/tcmalloc override jemalloc via cfg guards (same pattern as
sysmalloc), so--no-default-featuresis not needed despite jemalloc being hardcoded in the binary deps.Both features are unix-only enabling them on Windows produces a compile_error. Enabling both simultaneously also produces a compile_error.
Benchmarks
lcli transition-blockson a recent mainnet finalized block (10 runs,--exclude-cache-builds --exclude-post-block-thc):jemalloc and mimalloc are effectively identical on block processing. tcmalloc is ~6% slower. These numbers only cover
transition-blocksthough live node testing with sustained load and varying allocation patterns could show different results.Changes
common/malloc_utils/Cargo.tomladd mimalloc + tcmalloc optional deps and featurescommon/malloc_utils/src/lib.rsconditional compilation for new allocators, compile_error guards for invalid combinationscommon/malloc_utils/src/mimalloc_alloc.rsnew#[global_allocator]modulecommon/malloc_utils/src/tcmalloc_alloc.rsnew#[global_allocator]modulelighthouse/Cargo.tomlexpose mimalloc/tcmalloc featureslcli/Cargo.tomlexpose mimalloc/tcmalloc featuresAllocator metrics for mimalloc/tcmalloc are stubbed out can be filled in as a follow-up once we decide which allocator to invest in.