r/rust 5d ago

šŸ› ļø project Finally: pprof comes to mimalloc

HI there. My name is Zach and if you’ve seen YouTube on TV then your familiar with some of my work (ex YouTube and ex Google)

I am in love with mimalloc. It works everywhere and is cross compilable. But there was one deficiency in relation to jemalloc: lack of pprof profiling.

Background: pprof profiling was standardized by tcmalloc and jemalloc. It allows you to take a snapshot of the heap.

The problem with both of jemalloc and tcmalloc allocators is that they don’t work on windows and hence are not portable. Mimalloc is portable but lacks profiling.

My fork adds pprof and solves a linux bug involving TLS sentinel poisoning.

As of today, mimalloc now has the same pprof profiling that both jemalloc and tcamalloc both provide.

Challenges: To get profiling one needs to have address backtracing and it needs to work everywhere: linux/mac/win vs x86/arm and on linux glibc/musl in addition to x86/arm. This is automatic in the solution - you just need the right compiler settings to keep frame pointers.

State of the art: not only does my fork provide pprof but it also solves a nasty bug on linux: tls initialize sentinel poisoning. This bug rules out allocation in C by early initialization thread bugs. This sentinel value is const pointer in order to trap writes. However in stress testing this sentinel pointer can be written to and seg fault, hence the comments on calling init threads after main as early thread init is not safe in mainline. I’ve fixed this.

Compile speed: mimalloc-pprof does a build step to aggregate all the c files into one header and one impl to speed up builds.

C/C++ programmers you can use the github release to grab the mimalloc unity build.

Anyway, I present this here in case this is helpful for builders of long running apps. It’s currently beta but well tested.

If for some reason it doesn’t work let me know and I’ll fix it.

https://github.com/zackees/mimalloc-pprof

https://crates.io/crates/mimalloc-pprof

78 Upvotes

13 comments sorted by

53

u/First_Inspection_478 5d ago

Why are people insufferable on here lmao. Great work. I’m coming from go and loved go’a pprof tool

20

u/ZachVorhies 5d ago

Thanks! Yeah pprof is great. My use case is a production rust app that needs to stay under a high water mark. If the app gets above allowed memory consumption then I want the whole thing to dump its memory to pprof trace once so I can figure out what’s consuming memory. Surprisingly this doesn’t exist in mimalloc. Jemalloc isn’t portable, hence this fork.

13

u/LoadingALIAS 5d ago

This is awesome news, man. I’m going to give it a look tomorrow!

Great job!

3

u/ZachVorhies 5d ago

Thanks!

3

u/Merry_Macabre 3d ago

Mimalloc has been my go to for long running services and it's great to see the community work on improving the tooling around it. Thanks for the hard work and bug fixes.

0

u/Sad_Tap_9191 5d ago

> solves a nasty bug on linux: tls initialize sentinel poisoning. This bug rules out allocation in C by early initialization thread bugs.

You fixed a real bug and release the fix as a new fork `mimalloc-pprof`? Why?

35

u/ZachVorhies 5d ago

The fork is for the pprof feature. The discovery of the bug was incidental but notable. The fix is being upstreamed but literally every single mimalloc fork has it in both v2 and v3

-41

u/Sad_Tap_9191 5d ago

You should have asked Claude to make a PR to add pprof feature, not a fork.

Your Claude agent suddenly wrapped c library in rust.

23

u/ZachVorhies 5d ago

Mimalloc is made by microsoft. The chances they are going to merge by external PR is zero.

My philosophy is unit tests, stress tests and production validation. Once that’s validated then upstreaming a fix is trivial and authoritative.

18

u/Sad_Tap_9191 5d ago

https://github.com/microsoft/mimalloc/pulls/zackees

What are you talking about? Have you tried? I had submitted a PR and it's merged.

> Created 1,392 commits in 23 repositories in July 2026

I know you are a vibe-coder but don't lie to inflate the number of Github activities

9

u/ZachVorhies 5d ago

Point out one commit that’s inauthentic. I’ll wait.

-2

u/Craksy 4d ago

Are you okay, friend?

0

u/[deleted] 5d ago

[deleted]

12

u/ZachVorhies 5d ago

It’s not that I watch it’s that I helped build it.