Add bun_configure_mimalloc

This commit is contained in:
Kai Tamkun
2025-08-20 16:46:08 -07:00
parent b1417f494d
commit cf0bdce7d4
4 changed files with 14 additions and 3 deletions

View File

@@ -495,6 +495,7 @@ src/bun.js/modules/NodeTTYModule.cpp
src/bun.js/modules/NodeUtilTypesModule.cpp
src/bun.js/modules/ObjectModule.cpp
src/deps/libuwsockets.cpp
src/deps/mimalloc.cpp
src/io/io_darwin.cpp
src/vm/Semaphore.cpp
src/vm/SigintWatcher.cpp

View File

@@ -4,7 +4,7 @@ register_repository(
REPOSITORY
oven-sh/mimalloc
COMMIT
1beadf9651a7bfdec6b5367c380ecc3fe1c40d1a
2d81b6fee92def9f1aad72f7caad67243148b6ee
)
set(MIMALLOC_CMAKE_ARGS
@@ -14,7 +14,7 @@ set(MIMALLOC_CMAKE_ARGS
-DMI_BUILD_TESTS=OFF
-DMI_USE_CXX=ON
-DMI_SKIP_COLLECT_ON_EXIT=ON
# ```
# mimalloc_allow_large_os_pages=0 BUN_PORT=3004 mem bun http-hello.js
# Started development server: http://localhost:3004
@@ -51,7 +51,7 @@ if(ENABLE_ASAN)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_UBSAN=ON)
elseif(APPLE OR LINUX)
if(APPLE)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OVERRIDE=OFF)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OVERRIDE=OFF)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OSX_ZONE=OFF)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OSX_INTERPOSE=OFF)
else()

7
src/deps/mimalloc.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include "mimalloc.h"
#include <cstdio>
extern "C" void bun_configure_mimalloc()
{
mi_option_set(mi_option_generic_collect, 10'000); // default
}

View File

@@ -11,10 +11,13 @@ comptime {
extern fn bun_warn_avx_missing(url: [*:0]const u8) void;
extern fn bun_configure_mimalloc() void;
pub extern "c" var _environ: ?*anyopaque;
pub extern "c" var environ: ?*anyopaque;
pub fn main() void {
bun_configure_mimalloc();
bun.crash_handler.init();
if (Environment.isPosix) {