Linux/macOS: link mimalloc into executables; unify allocator helper#6183
Open
Grantim wants to merge 7 commits into
Open
Linux/macOS: link mimalloc into executables; unify allocator helper#6183Grantim wants to merge 7 commits into
Grantim wants to merge 7 commits into
Conversation
Brings mimalloc to native Linux (apt libmimalloc-dev) and macOS (brew mimalloc), and folds every platform into one per-target helper mr_enable_mimalloc() (Mimalloc.cmake, renamed from MimallocRedirect.cmake), gated by the single MESHLIB_USE_MIMALLOC option. Native platforms link the package's mimalloc target via find_package(mimalloc CONFIG); MRMesh.MimallocRedirectActive verifies the override actually engaged. Emscripten applies -sMALLOC=mimalloc per target (replacing the global flag and the MR_EMSCRIPTEN_MIMALLOC option). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…config CI showed find_package(mimalloc CONFIG REQUIRED) fails on ubuntu22 - its libmimalloc-dev has no mimalloc-config.cmake (ubuntu24 / brew / vcpkg do). Native now tries CONFIG, then falls back to find_library for that case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…imalloc The engagement test only checked C malloc in the test binary. Add an operator new[] check and a makeCube() allocation (operator new'd inside MRMesh) so it proves mimalloc reaches C++ allocations and the shared libraries - the actual goal, and the part the process-wide override must reach (esp. macOS). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…reason TEMPORARY - revert before merge. Trims the macOS matrix to the self-hosted arm64 Debug job (the one hitting the macOS-13 dyld abort) and adds MIMALLOC_VERBOSE / MIMALLOC_SHOW_ERRORS / DYLD_PRINT_INITIALIZERS plus a crash-report dump to the MeshViewer smoke step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… abort) brew's dynamic mimalloc 3.x aborts at launch on macOS <= 13: an allocation during libSystem init reaches mi_thread_init, which touches a thread-local before dyld bootstraps it (mi_thread_init -> _tlv_bootstrap -> dyld abort). Static-link via -force_load so mimalloc's init runs with this exe's own initializers (after libSystem). Linux keeps dynamic linking (works there). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d abort reason" This reverts commit 1c6cc82.
Fedr
approved these changes
May 29, 2026
oitel
reviewed
May 29, 2026
| set(_mi_saved_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||
| set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") | ||
| find_library(MR_MIMALLOC_STATIC NAMES mimalloc REQUIRED) | ||
| set(CMAKE_FIND_LIBRARY_SUFFIXES ${_mi_saved_suffixes}) |
Contributor
There was a problem hiding this comment.
Wouldn't the previous value be restored automatically since CMake functions create their own variable scopes?
| return() | ||
| endif() | ||
|
|
||
| if(EMSCRIPTEN OR MR_EMSCRIPTEN) |
Comment on lines
+20
to
+24
| if(_existing_libs) | ||
| set_property(TARGET ${target} PROPERTY LINK_LIBRARIES mimalloc ${_existing_libs}) | ||
| else() | ||
| set_property(TARGET ${target} PROPERTY LINK_LIBRARIES mimalloc) | ||
| endif() |
Contributor
There was a problem hiding this comment.
Aren't both branches functionally equivalent?
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.
Brings the mimalloc allocator to native Linux (apt
libmimalloc-dev) and macOS (brewmimalloc) executables, after Windows (#6172/#6173/#6176) and Emscripten (#6149).All four platforms now route through one per-target CMake helper
mr_enable_mimalloc()incmake/Modules/Mimalloc.cmake(renamed fromMimallocRedirect.cmake), gated by a singleMESHLIB_USE_MIMALLOCoption (default ON):mimalloc-redirect.dllimport-order redirect, unchanged.find_package(mimalloc CONFIG REQUIRED)+target_link_libraries(PRIVATE mimalloc).-sMALLOC=mimalloc, replacing the globalCMAKE_EXE_LINKER_FLAGSflag and theMR_EMSCRIPTEN_MIMALLOCoption (folded intoMESHLIB_USE_MIMALLOC).MRMesh.MimallocRedirectActivenow verifies engagement on all native platforms viami_is_in_heap_region(Windows also checksmi_is_redirected).Starting minimal: native just links the package's mimalloc target. If CI shows the override doesn't engage somewhere (link ordering,
-force_load,-u mi_version, ...), the specific fix gets added then — not preemptively.Note: cpp-examples / example_plugin and the exported
MESHLIB_EMSCRIPTEN_EXE_LINKER_FLAGSno longer force the allocator (now applied per app-target); intentional.Draft until CI is green across all platforms.