fix(sys): disable mimalloc v3 FIXED_SLOT TLS on macOS#67
Merged
Conversation
34caa61 to
a866ae2
Compare
a866ae2 to
ab9477f
Compare
This was referenced May 16, 2026
Boshen
pushed a commit
to oxc-project/oxc
that referenced
this pull request
May 17, 2026
See napi-rs/mimalloc-safe#67 & napi-rs/mimalloc-safe#68 If `oxlint` and `oxfmt` plan to adopt `mimalloc v3` in the future, this upgrade would be highly worthwhile and could bring meaningful performance and memory management improvements.
shulaoda
added a commit
to rolldown/rolldown
that referenced
this pull request
May 17, 2026
IWANABETHATGUY
pushed a commit
to rolldown/rolldown
that referenced
this pull request
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mimalloc v3 on macOS defaults to MI_TLS_MODEL_FIXED_SLOT, which stores the per-thread theap pointer in TCB[108]/[109] via inline assembly, bypassing pthread_setspecific. The slot is hardcoded and shared across all mimalloc instances in the same process.
In Node.js processes that dlopen multiple napi addons each statically linking mimalloc-safe (e.g. a CLI binding plus a separately loaded rolldown binding), each instance writes its own theap to the same TCB slot, corrupting the other's heap metadata. On tokio runtimes the most visible symptom is BlockingTask's Option discriminant byte getting clobbered, panicking with "blocking task ran twice".
Define MI_HAS_TLS_SLOT=0 for macOS targets when the v3 source tree is selected. This makes the platform cascade in prim.h skip the fixed-slot branch and fall through to MI_TLS_MODEL_DYNAMIC_PTHREADS, which uses pthread_getspecific — each dylib gets its own pthread_key, so multiple mimalloc instances coexist safely. The cost is an indirect function call per default-heap access (~3 ns -> ~10 ns); negligible in practice.
See c_src/mimalloc3/include/mimalloc/prim.h:345-349 caveat and the "@apple: it would be great to get 2 official slots for custom allocators" comment at line 374.