mi-malloc 3.6/2.5/1.15
Loading...
Searching...
No Matches
Getting the Best Performance

Consider the following build options (v3):

  • -DMI_OPT_ARCH=ON (the default on arm64) enables architecture-specific optimizations: -march=haswell -mavx2 on x64, -march=armv8.1-a on arm64, and -march=rv64gcb_zacas on RISC-V. These improve bit operations and atomic operations, but unsupported hardware or emulators may fail with an illegal instruction. Apple arm64 defaults to -march=armv8.3-a, supported on M1 and later, for efficient load-acquire instructions. RISC-V hardware supporting zalasr can use -DMI_OPT_ARCH=rv64gcb_zacas_zalasr.
  • -DMI_ALLOW_THP=OFF can significantly reduce resident memory usage for some programs.
  • -DMI_ALLOW_THP=FULL can significantly improve performance for some programs, but still respects an OS THP setting of [never].
  • -DMI_FREE_IS_CHECKED=ON checks pointers passed to mi_free(), at a small performance cost. This can be useful when overriding malloc/free process-wide. Alternatively, mi_cfree() always checks pointer validity. Pointer checking is always enabled at secure level CHECKED and higher.

In source code:

For runtimes and compilers, such as Koka, Lean, or Rust, prefer the constant-size or small-allocation APIs when sizes are known. If a runtime already carries thread-local state, it can cache mi_theap_get_default() for each thread and pass that thread's theap directly to mi_theap_malloc() or mi_theap_malloc_small(). This avoids repeatedly looking up the thread-local pointer and skips a NULL theap check. The benefit depends on the OS implementation of thread-local storage.