Skip to content

Conversation

@joseluisq
Copy link
Collaborator

@joseluisq joseluisq commented Nov 28, 2025

Description

This PR drops jemalloc (now archived) in favor of mimalloc allocator for MUSL targets (statically-linked binaries).
The change brings performance improvements and significant memory savings.

Generic benchmark tests

In the tests below, using mimalloc decreases ~68% RAM usage. But remember that this test is generic and could vary.

  • Intel Core i7 8GB
  • Linux 6.7.9-arch1-1
  • Rust 1.76.0

jemalloc (~32MB RAM)

$ wrk -c500 -t12 -d5s --latency http://localhost:8787
Running 5s test @ http://localhost:8787
  12 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.59ms   13.03ms 219.98ms   96.61%
    Req/Sec     3.54k     0.89k    7.59k    84.24%
  Latency Distribution
     50%    9.89ms
     75%   13.56ms
     90%   18.12ms
     99%   36.89ms
  208531 requests in 5.03s, 171.43MB read
Requests/sec:  41447.05
Transfer/sec:     34.07MB

mimalloc (~22MB RAM)

$ wrk -c500 -t12 -d5s --latency http://localhost:8787
Running 5s test @ http://localhost:8787
  12 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.15ms    5.34ms  51.04ms   73.07%
    Req/Sec     3.58k   753.06    10.94k    85.52%
  Latency Distribution
     50%   10.53ms
     75%   13.80ms
     90%   18.04ms
     99%   27.32ms
  212102 requests in 5.10s, 174.36MB read
Requests/sec:  41578.55
Transfer/sec:     34.18MB

Docker containers

The result using the latest joseluisq/static-web-server:2-alpine (jemalloc, ~30MB RAM) and a custom Alpine image (mimalloc ~22MB RAM) is a bit similar.

Targets affected

  • x86_64-unknown-linux-musl
  • i686-unknown-linux-musl
  • aarch64-unknown-linux-musl
  • arm-unknown-linux-musleabihf
  • armv7-unknown-linux-musleabihf

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

@joseluisq joseluisq added v2 v2 release performance Related to server performance dependency Related to dependencies linux Linux platform specific labels Nov 28, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Nov 28, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/bin/server.rs  5% smaller
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format

@joseluisq joseluisq self-assigned this Nov 28, 2025
@joseluisq joseluisq changed the title Drop jemalloc in favor of mimalloc for musl targets Drop jemalloc in favor of mimalloc allocator for MUSL targets Nov 28, 2025
@joseluisq joseluisq marked this pull request as ready for review November 28, 2025 00:30
@joseluisq joseluisq merged commit afddfd6 into master Nov 28, 2025
33 checks passed
@joseluisq joseluisq deleted the drop-jemalloc-in-favor-of-mimalloc branch November 28, 2025 00:38
@joseluisq joseluisq added this to the v2.40.0 milestone Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependency Related to dependencies linux Linux platform specific performance Related to server performance v2 v2 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants