You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MIMALLOC_SHOW_STATS=1 environment variable does not work on Linux #28630
Create a simple Bun script (e.g., index.ts): console.log("hello world");
Run the script with the MIMALLOC_SHOW_STATS=1 environment variable: MIMALLOC_SHOW_STATS=1 bun run index.ts
Observe that no mimalloc statistics are printed to the console
What is the expected behavior?
According to the Bun documentation, setting MIMALLOC_SHOW_STATS=1 should display mimalloc memory allocation statistics after the program exits, just as it does on macOS.
What do you see instead?
On Linux, no mimalloc statistics are printed at all. The program runs and exits normally without any memory stats output.
However, the same command works correctly on macOS and produces the expected mimalloc statistics.
Cause (updated after rebase): Bun builds mimalloc with MI_NO_PROCESS_DETACH=1, which disables mimalloc s automatic stats output on ALL platforms — not just Linux. The recent mimalloc update (v1.x → v3.3.1) also changed stats registration from atexit() to __attribute__((destructor)).
Fix: Print stats manually in Bun__onExit (runs on all platforms) when MIMALLOC_SHOW_STATS=1 or MIMALLOC_VERBOSE=1 is set.
USE_SYSTEM_BUN=1 bun test test/regression/issue/28630.test.ts → FAIL
bun bd test test/regression/issue/28630.test.ts → PASS
Why the env var prints nothing. Bun builds mimalloc with MI_NO_PROCESS_DETACH (scripts/build/deps/mimalloc.ts:56). That setting turns off the report that mimalloc prints at process exit, so MIMALLOC_SHOW_STATS=1 and MIMALLOC_VERBOSE=1 have no effect at exit.
Workaround. Print the same report from an exit handler:
process.on("exit",()=>Bun.unsafe.mimallocDump());
Bun.unsafe.mimallocDump() writes the mimalloc statistics to stderr. It is documented in Benchmarking. On 1.4.3-canary.1 (09bb546), MIMALLOC_SHOW_STATS=1 bun run index.ts prints nothing, and the same script with this handler prints the full report. The handler also runs on process.exit(n), and the exit code stays the same.
Without an edit to the program. Put the handler in a preload file. This version keeps the env var as the switch:
MIMALLOC_SHOW_STATS=1 bun run --preload ./dump.js index.ts
MIMALLOC_SHOW_STATS=1 BUN_OPTIONS=--preload=/absolute/path/to/dump.js bun run index.ts
A top-level preload = ["./dump.js"] in bunfig.toml also works. In BUN_OPTIONS, write --preload=<path> with the = sign.
What this does not cover. Commands that run no JavaScript, such as bun install, have no exit handler to hook. #28631 tried to restore the env var for every command. It was closed because its branch no longer builds on main and nobody has asked for that part. This issue stays open so that a maintainer can decide whether the env var itself should work again.
Closing as not planned. Bun turns off mimalloc's report at process exit on purpose, and the docs no longer point to MIMALLOC_SHOW_STATS (#33706 replaced that line with Bun.unsafe.mimallocDump()). The comment above has a workaround that prints the same report at exit, with or without an edit to the program.
If you need these statistics for a command that runs no JavaScript, such as bun install, reply here with the use case and this can be reopened.
Activity
robobun commentedon Mar 29, 2026
✅ Updated fix submitted in #28631.
Cause (updated after rebase): Bun builds mimalloc with
MI_NO_PROCESS_DETACH=1, which disables mimalloc s automatic stats output on ALL platforms — not just Linux. The recent mimalloc update (v1.x → v3.3.1) also changed stats registration fromatexit()to__attribute__((destructor)).Fix: Print stats manually in
Bun__onExit(runs on all platforms) whenMIMALLOC_SHOW_STATS=1orMIMALLOC_VERBOSE=1is set.USE_SYSTEM_BUN=1 bun test test/regression/issue/28630.test.ts→ FAILbun bd test test/regression/issue/28630.test.ts→ PASSfeat: add mi_heap_dump_json / mi_heap_get_seq and snapshot-safe stats…
robobun commentedon Sep 14, 2026
There is a workaround that works today.
Why the env var prints nothing. Bun builds mimalloc with
MI_NO_PROCESS_DETACH(scripts/build/deps/mimalloc.ts:56). That setting turns off the report that mimalloc prints at process exit, soMIMALLOC_SHOW_STATS=1andMIMALLOC_VERBOSE=1have no effect at exit.Workaround. Print the same report from an exit handler:
Bun.unsafe.mimallocDump()writes the mimalloc statistics to stderr. It is documented in Benchmarking. On 1.4.3-canary.1 (09bb546),MIMALLOC_SHOW_STATS=1 bun run index.tsprints nothing, and the same script with this handler prints the full report. The handler also runs onprocess.exit(n), and the exit code stays the same.Without an edit to the program. Put the handler in a preload file. This version keeps the env var as the switch:
Each of these loads it:
A top-level
preload = ["./dump.js"]inbunfig.tomlalso works. InBUN_OPTIONS, write--preload=<path>with the=sign.What this does not cover. Commands that run no JavaScript, such as
bun install, have no exit handler to hook. #28631 tried to restore the env var for every command. It was closed because its branch no longer builds on main and nobody has asked for that part. This issue stays open so that a maintainer can decide whether the env var itself should work again.robobun commentedon Sep 14, 2026
Closing as not planned. Bun turns off mimalloc's report at process exit on purpose, and the docs no longer point to
MIMALLOC_SHOW_STATS(#33706 replaced that line withBun.unsafe.mimallocDump()). The comment above has a workaround that prints the same report at exit, with or without an edit to the program.If you need these statistics for a command that runs no JavaScript, such as
bun install, reply here with the use case and this can be reopened.