Skip to content

Comments

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

Open
0xMars42 wants to merge 1 commit intosigp:unstablefrom
0xMars42:feat-test-allocators
Open

feat(malloc_utils): add mimalloc and tcmalloc allocator feature flags#8884
0xMars42 wants to merge 1 commit 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):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants