Commit 2511176
Add opt-in MI_SINGLE_THREADED specialization for the free fast path
In a program that only ever uses mimalloc from a single thread, every
freed block is guaranteed to be thread-local, so the per-free thread
ownership check in mi_free_ex (a thread-id TLS read, a relaxed atomic
load of segment->thread_id, and a compare) is redundant.
This adds an opt-in, off-by-default compile-time switch
(-DMI_SINGLE_THREADED=1) that forces is_local=true and skips that check.
The default build is unchanged (the #else path is identical to before
and the full multi-threaded test suite still passes).
Measured on a single-threaded, allocation-heavy workload (mimalloc-bench
alloc-test, 1 thread, pinned, interleaved median-of-11): ~0.4% faster
wall time, with perf showing ~2.5% fewer branches and ~1.1% fewer
instructions (the eliminated per-free ownership branch). cfrac/espresso
output is byte-identical to baseline.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 9285427 commit 2511176
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
156 | 162 | | |
| 163 | + | |
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
| |||
0 commit comments