Skip to content

Use jemalloc as global allocator on Linux#179

Merged
rocketman-code merged 1 commit intomainfrom
perf/jemalloc-linux
Feb 27, 2026
Merged

Use jemalloc as global allocator on Linux#179
rocketman-code merged 1 commit intomainfrom
perf/jemalloc-linux

Conversation

@rocketman-code
Copy link
Owner

Summary

  • Add tikv-jemallocator as a Linux-only dependency via target-conditional [target.'cfg(target_os = "linux")'.dependencies]
  • Set jemalloc as the global allocator on Linux only (#[cfg(target_os = "linux")])
  • macOS never compiles jemalloc (zero impact on non-Linux builds)

Benchmark

A/B on Linux VPS (wrangler cold, 3447 modules, --no-cache):

Allocator Wall time System time
system (musl) 531ms 267ms
jemalloc 329ms 134ms

1.61x faster. System time halved — musl's allocator makes 3,200+ mmap/munmap/brk syscalls for chainsaw's workload; jemalloc services the same with 23.

macOS is neutral (libmalloc is already magazine-based).

Test plan

  • cargo test --workspace passes (274 tests)
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • Cross-compiled for x86_64-unknown-linux-musl, verified jemalloc linked
  • A/B benchmarked on Linux VPS with hyperfine (30 runs, warmup 3)
  • Verified macOS build does not compile jemalloc

Closes #178

musl's allocator makes 3,200+ mmap/munmap/brk syscalls for chainsaw's
workload (~64 allocs/file, 85% <= 64 bytes). jemalloc services the same
workload with 23 syscalls.

A/B on Linux VPS (wrangler cold, 3447 modules): 531ms -> 329ms (1.61x).
macOS is neutral (libmalloc is already magazine-based).

Uses target-conditional dep so macOS never compiles jemalloc.

Closes #178
@rocketman-code rocketman-code merged commit b87961c into main Feb 27, 2026
8 checks passed
@rocketman-code rocketman-code deleted the perf/jemalloc-linux branch February 27, 2026 18:42
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.

Use jemalloc on Linux for faster cold builds

1 participant