@@ -12,6 +12,7 @@ option(NFX_ENABLE_AVX512 "Enable AVX-512 optimizations (requires CPU support)" O
1212option (NFX_ENABLE_IO_URING "Enable io_uring transport (Linux only)" OFF )
1313option (NFX_ENABLE_LOGGING "Enable Quill high-performance logging" ON )
1414option (NFX_ENABLE_ABSEIL "Enable Abseil for Swiss Table hash maps (~3x faster)" ON )
15+ option (NFX_ENABLE_MIMALLOC "Enable mimalloc allocator for per-session heaps" OFF )
1516option (NFX_BUILD_BENCHMARKS "Build benchmarks" ON )
1617option (NFX_BUILD_TESTS "Build tests" ON )
1718option (NFX_BUILD_EXAMPLES "Build examples" ON )
@@ -44,6 +45,20 @@ if(NFX_ENABLE_ABSEIL)
4445 FetchContent_MakeAvailable (abseil-cpp)
4546endif ()
4647
48+ # mimalloc - Microsoft's high-performance allocator (per-session heaps, O(1) cleanup)
49+ if (NFX_ENABLE_MIMALLOC)
50+ FetchContent_Declare (
51+ mimalloc
52+ GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
53+ GIT_TAG v2.1.7
54+ GIT_SHALLOW TRUE
55+ )
56+ set (MI_BUILD_SHARED OFF CACHE BOOL "" FORCE )
57+ set (MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE )
58+ set (MI_BUILD_TESTS OFF CACHE BOOL "" FORCE )
59+ FetchContent_MakeAvailable (mimalloc)
60+ endif ()
61+
4762# Platform-specific compiler flags
4863if (MSVC )
4964 # MSVC flags
@@ -175,6 +190,13 @@ if(NFX_ENABLE_ABSEIL)
175190 message (STATUS "Abseil Swiss Tables enabled (~3x faster hash map lookups)" )
176191endif ()
177192
193+ # mimalloc allocator support (per-session heaps)
194+ if (NFX_ENABLE_MIMALLOC)
195+ target_link_libraries (nexusfix INTERFACE mimalloc-static )
196+ target_compile_definitions (nexusfix INTERFACE NFX_HAS_MIMALLOC=1 )
197+ message (STATUS "mimalloc allocator enabled (per-session heaps, O(1) cleanup)" )
198+ endif ()
199+
178200# io_uring support (Linux only)
179201if (NFX_ENABLE_IO_URING AND CMAKE_SYSTEM_NAME STREQUAL "Linux" )
180202 find_package (PkgConfig REQUIRED )
@@ -216,7 +238,7 @@ endif()
216238# Install targets (only when no FetchContent dependencies are linked)
217239# Quill and Abseil don't provide export sets, so we can only export
218240# the pure header-only library without these dependencies
219- if (NOT NFX_ENABLE_LOGGING AND NOT NFX_ENABLE_ABSEIL)
241+ if (NOT NFX_ENABLE_LOGGING AND NOT NFX_ENABLE_ABSEIL AND NOT NFX_ENABLE_MIMALLOC )
220242 include (GNUInstallDirs )
221243 install (TARGETS nexusfix
222244 EXPORT nexusfixTargets
0 commit comments