Skip to content

Commit 15b7cb1

Browse files
Alan-StratCraftsAIstarvian
authored andcommitted
Implement TICKET_210: mimalloc per-session heap integration
Add SessionHeap combining monotonic bump allocation with mimalloc upstream for 64% faster burst allocation and graceful overflow handling.
1 parent 801e67b commit 15b7cb1

9 files changed

Lines changed: 1650 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(NFX_ENABLE_AVX512 "Enable AVX-512 optimizations (requires CPU support)" O
1212
option(NFX_ENABLE_IO_URING "Enable io_uring transport (Linux only)" OFF)
1313
option(NFX_ENABLE_LOGGING "Enable Quill high-performance logging" ON)
1414
option(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)
1516
option(NFX_BUILD_BENCHMARKS "Build benchmarks" ON)
1617
option(NFX_BUILD_TESTS "Build tests" ON)
1718
option(NFX_BUILD_EXAMPLES "Build examples" ON)
@@ -44,6 +45,20 @@ if(NFX_ENABLE_ABSEIL)
4445
FetchContent_MakeAvailable(abseil-cpp)
4546
endif()
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
4863
if(MSVC)
4964
# MSVC flags
@@ -175,6 +190,13 @@ if(NFX_ENABLE_ABSEIL)
175190
message(STATUS "Abseil Swiss Tables enabled (~3x faster hash map lookups)")
176191
endif()
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)
179201
if(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

benchmarks/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,24 @@ set_target_properties(structural_index_bench PROPERTIES
224224
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/benchmarks
225225
)
226226

227+
# mimalloc vs PMR benchmark (optional, requires NFX_ENABLE_MIMALLOC=ON)
228+
if(NFX_ENABLE_MIMALLOC)
229+
add_executable(mimalloc_bench mimalloc_bench.cpp)
230+
target_link_libraries(mimalloc_bench PRIVATE nexusfix pthread)
231+
target_include_directories(mimalloc_bench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
232+
target_compile_options(mimalloc_bench PRIVATE -O3 -march=native)
233+
set_target_properties(mimalloc_bench PROPERTIES
234+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/benchmarks
235+
)
236+
237+
add_executable(session_heap_isolation_bench session_heap_isolation_bench.cpp)
238+
target_link_libraries(session_heap_isolation_bench PRIVATE nexusfix pthread)
239+
target_include_directories(session_heap_isolation_bench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
240+
target_compile_options(session_heap_isolation_bench PRIVATE -O3 -march=native)
241+
set_target_properties(session_heap_isolation_bench PROPERTIES
242+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/benchmarks
243+
)
244+
endif()
245+
227246
# QuickFIX comparison benchmark (optional)
228247
add_subdirectory(vs_quickfix)

0 commit comments

Comments
 (0)