Skip to content

feat(malloc_utils): add mimalloc and tcmalloc allocator feature flags#8884

Open
0xMars42 wants to merge 4 commits intosigp:unstablefrom
0xMars42:feat-test-allocators
Open

feat(malloc_utils): add mimalloc and tcmalloc allocator feature flags#8884
0xMars42 wants to merge 4 commits intosigp:unstablefrom
0xMars42:feat-test-allocators

Conversation

@0xMars42
Copy link

@0xMars42 0xMars42 commented Feb 23, 2026

Closes #8840

Adds mimalloc and tcmalloc feature flags to malloc_utils, lighthouse, and lcli crates.

Usage

cargo build --release -p lighthouse --features mimalloc
cargo build --release -p lighthouse --features tcmalloc

mimalloc/tcmalloc override jemalloc via cfg guards (same pattern as sysmalloc), so --no-default-features is 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-blocks on a recent mainnet finalized block (10 runs, --exclude-cache-builds --exclude-post-block-thc):

Allocator Median Min Max
jemalloc 1001ms 982ms 1051ms
mimalloc 1002ms 970ms 1171ms
tcmalloc 1066ms 1041ms 1191ms

jemalloc and mimalloc are effectively identical on block processing. tcmalloc is ~6% slower. These numbers only cover transition-blocks though live node testing with sustained load and varying allocation patterns could show different results.

Changes

  • common/malloc_utils/Cargo.toml add mimalloc + tcmalloc optional deps and features
  • common/malloc_utils/src/lib.rs conditional compilation for new allocators, compile_error guards for invalid combinations
  • common/malloc_utils/src/mimalloc_alloc.rs new #[global_allocator] module
  • common/malloc_utils/src/tcmalloc_alloc.rs new #[global_allocator] module
  • lighthouse/Cargo.toml expose mimalloc/tcmalloc features
  • lcli/Cargo.toml expose mimalloc/tcmalloc features

Allocator metrics for mimalloc/tcmalloc are stubbed out can be filled in as a follow-up once we decide which allocator to invest in.

@cla-assistant
Copy link

cla-assistant bot commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

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
@0xMars42 0xMars42 force-pushed the feat-test-allocators branch from 962bbcd to c8da760 Compare February 23, 2026 04:44
@michaelsproul
Copy link
Member

Please familiarise yourself with our policy regarding AI contributions (currently in review but likely to be merged very soon):

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@michaelsproul michaelsproul added enhancement New feature or request waiting-on-author The reviewer has suggested changes and awaits thier implementation. code-quality optimization Something to make Lighthouse run more efficiently. labels Feb 24, 2026
@michaelsproul
Copy link
Member

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.

@0xMars42
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality enhancement New feature or request optimization Something to make Lighthouse run more efficiently. waiting-on-author The reviewer has suggested changes and awaits thier implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants