nervosnetwork / nervosnetwork/ckb
One allocator across Linux, macOS and Windows builds
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 266
- Avg merge
- 10d 5h
- Merged PRs (30d)
- 4
Description
The value of integrating
CKB runs jemalloc on Linux only: src/main.rs gates the #[global_allocator] on #[cfg(all(not(target_env = "msvc"), not(target_os = "macos")))], with tikv-jemallocator = "0.5.0". The macOS and Windows binaries you publish fall back to magazine malloc and the Windows Heap, so the same ckb run has three different allocators depending on which release an operator downloaded.
The node underneath is not lightly loaded. Block validation writes through ckb-rocksdb (pinned =0.21.1), and the tree carries rayon, crossbeam and dashmap — so frees regularly happen on a thread that did not do the allocation, and the allocator's cross-thread path is on the hot path of a sync.
rusty_alloc is a single allocator that behaves the same on all three, with 8,851 downloads on crates.io, in safe Rust with no C toolchain and no cfg gate to maintain. On that cross-thread path the rusty_alloc README measures 0.83x mimalloc's instructions (xthread — every free performed by a non-owning thread).
Not asking you to drop jemalloc on Linux — this would sit behind an off-by-default feature.
How to integrate
[features]
rusty-alloc = ["dep:rusty_alloc-api"] # opt in; default build unchanged
[dependencies]
rusty_alloc-api = { version = "2.1", optional = true }
Then in src/main.rs, beside the existing static:
#[cfg(feature = "rusty-alloc")]
#[global_allocator]
static ALLOC: rusty_alloc_api::RustyAlloc = rusty_alloc_api::RustyAlloc;
Nothing else changes: same consensus, same store, same RPC surface. Because it carries no platform exclusions, the macOS and Windows builds would get the same allocator as Linux for the first time — which is the part worth testing even if you keep jemalloc as the Linux default.
Remade With Rust & MATA
We are rebuilding the common C dependencies of the Rust ecosystem in safe Rust — allocators, compression, codecs, parsers, identity and storage — so a build can drop its C pieces without losing performance. Everything is at https://github.com/Remade-With-Rust, in case something else there is a better fit than this. If it is not for you, please close the issue.
- x.com/farmer_timmm
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the allocator cfg and existing static in src/main.rs, then review the feature and optional dependency declarations shown in the issue. Compare the Linux, macOS, and Windows build paths, keeping the default build unchanged. Done means the opt-in rusty-alloc configuration builds across all three platforms without changing consensus, storage, or RPC behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, build-system, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100