From 1d65722d065587777a8fa0a8ef8980cba25de9bd Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 05:37:08 +0000 Subject: [PATCH 1/7] Add Linux mimalloc build matrix entries (amd64/arm64, release + LTO) Adds a USE_EXTERNAL_MIMALLOC CMake option (requires USE_MIMALLOC=ON) that compiles bmalloc/WTF/JSC against the mimalloc v3 headers but leaves every mi_* symbol unresolved in libbmalloc.a/libWTF.a/libJavaScriptCore.a. Bun links its own vendored mimalloc (oven-sh/mimalloc) to satisfy them, so a second copy is not archived into the WebKit tarball. The vendored mimalloc object library is still built and linked into the jsc shell directly so bin/jsc stays runnable. Wires the option through Dockerfile and release.sh as build args, and adds four Linux glibc matrix entries (amd64/arm64 x release/LTO) plus the matching download/rename/release steps. Also drops an unused #include from StructureAlignedMemoryAllocator.cpp; the include path for it was never wired into JavaScriptCore and nothing from that header is referenced. --- .github/workflows/build-reusable.yml | 62 ++++++++++++++++++- Dockerfile | 6 ++ .../heap/StructureAlignedMemoryAllocator.cpp | 1 - Source/JavaScriptCore/shell/CMakeLists.txt | 7 +++ Source/bmalloc/CMakeLists.txt | 2 +- Source/cmake/WebKitFeatures.cmake | 2 + release.sh | 4 ++ 7 files changed, 81 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-reusable.yml b/.github/workflows/build-reusable.yml index db823f3d36c95..1535f987aeeaf 100644 --- a/.github/workflows/build-reusable.yml +++ b/.github/workflows/build-reusable.yml @@ -112,6 +112,42 @@ jobs: CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" ENABLE_SANITIZERS: "address,undefined" + # mimalloc variants: USE_MIMALLOC=ON routes bmalloc/FastMalloc through + # mimalloc instead of libpas. USE_EXTERNAL_MIMALLOC=ON leaves the + # mi_* symbols unresolved in the shipped archives so Bun's own + # vendored mimalloc (oven-sh/mimalloc) satisfies them at link time. + - lto_flag: "" + label: bun-webkit-linux-amd64-mimalloc + os: linux-x64-gh + package_json_arch: "x64" + CMAKE_BUILD_TYPE: "Release" + RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" + - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" + label: bun-webkit-linux-amd64-mimalloc-lto + os: linux-x64-gh + package_json_arch: "x64" + CMAKE_BUILD_TYPE: "Release" + RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" + - lto_flag: "" + label: bun-webkit-linux-arm64-mimalloc + os: linux-arm64-gh + package_json_arch: "arm64" + CMAKE_BUILD_TYPE: "Release" + RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" + - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" + label: bun-webkit-linux-arm64-mimalloc-lto + os: linux-arm64-gh + package_json_arch: "arm64" + CMAKE_BUILD_TYPE: "Release" + RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" timeout-minutes: 90 steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 @@ -137,7 +173,7 @@ jobs: else export MARCH_FLAG="${{ matrix.MARCH_FLAG || '-march=haswell' }}" fi - WEBKIT_RELEASE_TYPE=${{matrix.CMAKE_BUILD_TYPE}} CPU="native" cpu=native LTO_FLAG="${{matrix.lto_flag}}" temp=${{runner.temp}} ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" bash release.sh + WEBKIT_RELEASE_TYPE=${{matrix.CMAKE_BUILD_TYPE}} CPU="native" cpu=native LTO_FLAG="${{matrix.lto_flag}}" temp=${{runner.temp}} ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" bash release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["linux"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -696,6 +732,22 @@ jobs: with: name: bun-webkit-linux-arm64-lto path: ${{runner.temp}}/bun-webkit-linux-arm64-lto + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: bun-webkit-linux-amd64-mimalloc + path: ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: bun-webkit-linux-amd64-mimalloc-lto + path: ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc-lto + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: bun-webkit-linux-arm64-mimalloc + path: ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: bun-webkit-linux-arm64-mimalloc-lto + path: ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc-lto - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: bun-webkit-linux-amd64-baseline @@ -822,6 +874,10 @@ jobs: mv ${{runner.temp}}/bun-webkit-macos-amd64-debug/bun-webkit.tar.gz ./out/bun-webkit-macos-amd64-debug.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-arm64-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-lto.tar.gz + mv ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-mimalloc.tar.gz + mv ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-mimalloc-lto.tar.gz + mv ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-mimalloc.tar.gz + mv ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-mimalloc-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-baseline/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-baseline.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-baseline-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-baseline-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-musl-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-musl-lto.tar.gz @@ -872,6 +928,10 @@ jobs: ./out/bun-webkit-linux-arm64-debug.tar.gz ./out/bun-webkit-linux-amd64-debug-asan.tar.gz ./out/bun-webkit-linux-arm64-debug-asan.tar.gz + ./out/bun-webkit-linux-amd64-mimalloc.tar.gz + ./out/bun-webkit-linux-amd64-mimalloc-lto.tar.gz + ./out/bun-webkit-linux-arm64-mimalloc.tar.gz + ./out/bun-webkit-linux-arm64-mimalloc-lto.tar.gz - uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15 with: diff --git a/Dockerfile b/Dockerfile index 9687c2f525f5e..d49032e792fd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ ARG RELEASE_FLAGS="-O3 -DNDEBUG=1" ARG LLVM_VERSION="21" ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -g -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 " ARG ENABLE_SANITIZERS="" +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" # Use different base images for ARM64 vs x86_64 FROM --platform=$BUILDPLATFORM ubuntu:20.04 as base-arm64 @@ -21,6 +23,8 @@ ARG LLVM_VERSION ARG DEFAULT_CFLAGS ARG TARGETARCH ARG ENABLE_SANITIZERS +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC # Prevent interactive prompts ENV DEBIAN_FRONTEND=noninteractive @@ -280,6 +284,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DICU_ROOT=/icu \ -DENABLE_SANITIZERS="$ENABLE_SANITIZERS" \ -DENABLE_ASSERTS="$ENABLE_ASSERTS" \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -G Ninja \ /webkit && \ cd /webkitbuild && \ diff --git a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp index 154187f301bd6..1494c4a2f50d7 100644 --- a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp +++ b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp @@ -48,7 +48,6 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN #include #elif USE(MIMALLOC) #include -#include #endif WTF_ALLOW_UNSAFE_BUFFER_USAGE_END #endif diff --git a/Source/JavaScriptCore/shell/CMakeLists.txt b/Source/JavaScriptCore/shell/CMakeLists.txt index 58e7b833d717b..2a3970cd0d66f 100644 --- a/Source/JavaScriptCore/shell/CMakeLists.txt +++ b/Source/JavaScriptCore/shell/CMakeLists.txt @@ -18,6 +18,13 @@ if (WIN32) list(APPEND jsc_LIBRARIES Winmm) endif () +if (USE_EXTERNAL_MIMALLOC) + # The shipped static archives intentionally leave mi_* unresolved so the + # consumer links its own mimalloc. The jsc shell still needs a working + # allocator, so link the vendored mimalloc object library here only. + list(APPEND jsc_LIBRARIES $) +endif () + if (ENABLE_FUZZILLI) list(APPEND jsc_SOURCES ../fuzzilli/Fuzzilli.cpp) endif () diff --git a/Source/bmalloc/CMakeLists.txt b/Source/bmalloc/CMakeLists.txt index f181d7485e11f..3c60efcd604fa 100644 --- a/Source/bmalloc/CMakeLists.txt +++ b/Source/bmalloc/CMakeLists.txt @@ -657,7 +657,7 @@ if (ATOMICS_REQUIRE_LIBATOMIC) list(APPEND bmalloc_LIBRARIES atomic) endif () -if (USE_MIMALLOC) +if (USE_MIMALLOC AND NOT USE_EXTERNAL_MIMALLOC) list(APPEND bmalloc_LIBRARIES $) endif () diff --git a/Source/cmake/WebKitFeatures.cmake b/Source/cmake/WebKitFeatures.cmake index 84529bf3cf7d9..d949d65684023 100644 --- a/Source/cmake/WebKitFeatures.cmake +++ b/Source/cmake/WebKitFeatures.cmake @@ -308,6 +308,7 @@ macro(WEBKIT_OPTION_BEGIN) WEBKIT_OPTION_DEFINE(USE_SKIA_ENCODERS "Whether to use Skia image encoders" PRIVATE ON) WEBKIT_OPTION_DEFINE(USE_SYSTEM_MALLOC "Toggle system allocator instead of WebKit's custom allocator" PRIVATE ${USE_SYSTEM_MALLOC_DEFAULT}) WEBKIT_OPTION_DEFINE(USE_MIMALLOC "Toggle mimalloc instead of WebKit's custom allocator" PRIVATE ${USE_MIMALLOC_DEFAULT}) + WEBKIT_OPTION_DEFINE(USE_EXTERNAL_MIMALLOC "Compile against mimalloc headers but leave mi_* symbols unresolved in the static archives (caller links its own mimalloc). Implies USE_MIMALLOC." PRIVATE OFF) WEBKIT_OPTION_DEFINE(USE_PGO_PROFILE "Use PGO profile data for optimization (set PGO_PROFILE_PATH)" PRIVATE OFF) WEBKIT_OPTION_DEFINE(USE_WOFF2 "Toggle support for WOFF2 Web Fonts through libwoff2" PRIVATE ON) @@ -336,6 +337,7 @@ macro(WEBKIT_OPTION_BEGIN) WEBKIT_OPTION_DEPEND(ENABLE_WEBXR_HIT_TEST ENABLE_WEBXR) WEBKIT_OPTION_DEPEND(ENABLE_WEBXR_LAYERS ENABLE_WEBXR) WEBKIT_OPTION_DEPEND(USE_SKIA_ENCODERS USE_SKIA) + WEBKIT_OPTION_DEPEND(USE_EXTERNAL_MIMALLOC USE_MIMALLOC) endmacro() function(_WEBKIT_OPTION_ENFORCE_DEPENDS _name _resultvar) diff --git a/release.sh b/release.sh index d97b0d32897c5..160139a481a1e 100644 --- a/release.sh +++ b/release.sh @@ -54,6 +54,8 @@ export DEBIAN_VERSION="bookworm" export temp=${temp:-"$(mktemp -d -t bun-webkit-linux-$BUILDKIT_ARCH-release-$(date +%s)-XXXX)"} export ENABLE_SANITIZERS=${ENABLE_SANITIZERS:-} +export USE_MIMALLOC=${USE_MIMALLOC:-"OFF"} +export USE_EXTERNAL_MIMALLOC=${USE_EXTERNAL_MIMALLOC:-"OFF"} mkdir -p $temp rm -rf $temp/bun-webkit @@ -69,6 +71,8 @@ docker buildx build \ --build-arg RELEASE_FLAGS="$RELEASE_FLAGS" \ --build-arg WEBKIT_RELEASE_TYPE=$WEBKIT_RELEASE_TYPE \ --build-arg RELEASE_FLAGS="${RELEASE_FLAGS:-"-O2 -DNDEBUG=1"}" \ + --build-arg USE_MIMALLOC="$USE_MIMALLOC" \ + --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ --progress=plain \ --platform=linux/$BUILDKIT_ARCH \ --target=artifact \ From 22b4f7cd40c0dce65973b3dcc54689fa58c5a213 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 05:55:32 +0000 Subject: [PATCH 2/7] Dockerfile: unset C_INCLUDE_PATH for the WebKit build step C_INCLUDE_PATH points at gcc-13's compiler-builtin header directory. clang searches it ahead of its own resource dir, so any C translation unit that includes resolves to gcc's incompatible copy and fails to compile. mimalloc's static.c hits this under -march=haswell via bits.h. clang ships its own freestanding and intrinsic headers, so the gcc directory is not needed here. --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index d49032e792fd6..2d57157dc9a06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -253,7 +253,11 @@ ENV CPU=${CPU} ENV MARCH_FLAG=${MARCH_FLAG} ENV RELEASE_FLAGS=${RELEASE_FLAGS} +# clang searches C_INCLUDE_PATH (gcc-13's builtin-header dir) before its own +# resource dir, so C TUs including (mimalloc static.c, -march=haswell) +# pick up gcc's incompatible copy. clang ships its own; drop it for this step. RUN --mount=type=tmpfs,target=/webkitbuild \ + unset C_INCLUDE_PATH && \ export CFLAGS="$CFLAGS $LTO_FLAG -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \ export CXXFLAGS="$CXXFLAGS $LTO_FLAG -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \ export ENABLE_ASSERTS="AUTO" && \ From f625cc549093f75fda66b4e65401f781767bc6c0 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 09:09:58 +0000 Subject: [PATCH 3/7] StructureAlignedMemoryAllocator: fix mimalloc structure-heap arena under fork() and Malloc=1 Two bugs in the USE(MIMALLOC) path: 1. OSAllocator::tryReserveUncommittedAligned applies MADV_DONTFORK to the structure-heap reservation on Linux. mi_manage_os_memory_ex stores mi_arena_t and per-thread theap structs inside that region and registers them in mimalloc's process-wide subproc->arenas[] and subproc->heaps lists, which _mi_process_fork_child walks in the child before exec. After fork() those pages are unmapped in the child, so the walk segfaults. Undo DONTFORK on the region after registering it with mimalloc. 2. The mimalloc branch ran unconditionally without the m_useSystemHeap guard the libpas branch has. With Malloc=1 (m_useSystemHeap=true), tryMallocStructureBlock uses the bitvector fallback while the constructor still created a mimalloc arena whose mi_arena_t sits at the 64KiB-aligned start of the passed range; the bitvector was also never seeded with set(0), so it handed out block 0 (empty-StructureID conflict) and block 4 (overwriting mi_arena_t). Guard on m_useSystemHeap and seed the bitvector in the else branch, matching libpas. Also drive mimalloc's purge from Heap::didFinishCollection after a full GC via releaseFastMallocFreeMemoryForThisThread, since mimalloc has no background scavenger and otherwise only purges from allocation slow paths. --- Source/JavaScriptCore/heap/Heap.cpp | 8 +++++++ .../heap/StructureAlignedMemoryAllocator.cpp | 22 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index 919148bf34c67..c3b1824cc9f3b 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -104,6 +104,7 @@ #include #include #include +#include #include #include #include @@ -2632,6 +2633,13 @@ void Heap::didFinishCollection() for (auto* observer : m_observers) observer->didGarbageCollect(scope); + +#if USE(MIMALLOC) + // libpas runs a scavenger thread; mimalloc only purges from alloc + // slow-paths, so drive it here after a full GC freed FastMalloc memory. + if (scope == CollectionScope::Full) + WTF::releaseFastMallocFreeMemoryForThisThread(); +#endif } void Heap::resumeCompilerThreads() diff --git a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp index 1494c4a2f50d7..3057877e03c69 100644 --- a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp +++ b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp @@ -48,6 +48,10 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN #include #elif USE(MIMALLOC) #include +#if OS(LINUX) +#include +#include +#endif #endif WTF_ALLOW_UNSAFE_BUFFER_USAGE_END #endif @@ -135,10 +139,20 @@ class StructureMemoryManager { } m_usedBlocks.set(0); #elif USE(MIMALLOC) - void* memory = reinterpret_cast(reinterpret_cast(g_jscConfig.startOfStructureHeap) + MarkedBlock::blockSize); - size_t size = g_jscConfig.sizeOfStructureHeap - MarkedBlock::blockSize; - RELEASE_ASSERT(mi_manage_os_memory_ex(memory, size, false, false, false, -1, true, &structureArena)); - structureHeap = mi_heap_new_in_arena(structureArena); + if (!m_useSystemHeap) [[likely]] { + void* memory = reinterpret_cast(reinterpret_cast(g_jscConfig.startOfStructureHeap) + MarkedBlock::blockSize); + size_t size = g_jscConfig.sizeOfStructureHeap - MarkedBlock::blockSize; + RELEASE_ASSERT(mi_manage_os_memory_ex(memory, size, false, false, false, -1, true, &structureArena)); + structureHeap = mi_heap_new_in_arena(structureArena); +#if OS(LINUX) && defined(MADV_DOFORK) + // Undo tryReserveUncommittedAligned's MADV_DONTFORK: mimalloc stores + // mi_arena_t and theaps inside this region and registers them in + // process-wide lists that _mi_process_fork_child walks pre-exec. + while (madvise(reinterpret_cast(g_jscConfig.startOfStructureHeap), g_jscConfig.sizeOfStructureHeap, MADV_DOFORK) == -1 && errno == EAGAIN) { } +#endif + return; + } + m_usedBlocks.set(0); #else m_usedBlocks.set(0); #endif From 8e7b610ebc7adce1a20020d9218aa297378761f3 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 09:59:18 +0000 Subject: [PATCH 4/7] Enable USE_MIMALLOC/USE_EXTERNAL_MIMALLOC on all non-asan release targets Replaces the four separate -mimalloc Linux matrix entries with USE_MIMALLOC=ON + USE_EXTERNAL_MIMALLOC=ON on every non-asan, non-debug release target across linux (glibc, musl, android), macos, windows and freebsd. The -mimalloc archive name suffix is dropped; the regular release archives now ship with mi_* symbols unresolved for the consumer to link its own mimalloc. --- .github/workflows/build-reusable.yml | 120 ++++++++++++--------------- Dockerfile.android | 6 ++ Dockerfile.freebsd | 6 ++ Dockerfile.macos | 6 ++ Dockerfile.musl | 6 ++ Dockerfile.windows | 6 ++ android-release.sh | 4 + freebsd-release.sh | 4 + macos-cross-release.sh | 4 + musl-release.sh | 5 +- windows-cross-release.sh | 4 + 11 files changed, 105 insertions(+), 66 deletions(-) diff --git a/.github/workflows/build-reusable.yml b/.github/workflows/build-reusable.yml index 1535f987aeeaf..1c71527296e04 100644 --- a/.github/workflows/build-reusable.yml +++ b/.github/workflows/build-reusable.yml @@ -66,24 +66,32 @@ jobs: package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-arm64 os: linux-arm64-gh package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" label: bun-webkit-linux-amd64-lto os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-amd64 os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" label: bun-webkit-linux-amd64-baseline-lto os: linux-x64-gh @@ -91,6 +99,8 @@ jobs: CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" MARCH_FLAG: "-march=nehalem" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-amd64-baseline os: linux-x64-gh @@ -98,6 +108,8 @@ jobs: CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" MARCH_FLAG: "-march=nehalem" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-amd64-asan os: linux-x64-gh @@ -112,42 +124,6 @@ jobs: CMAKE_BUILD_TYPE: "Release" RELEASE_FLAGS: "-O3 -DNDEBUG=1" ENABLE_SANITIZERS: "address,undefined" - # mimalloc variants: USE_MIMALLOC=ON routes bmalloc/FastMalloc through - # mimalloc instead of libpas. USE_EXTERNAL_MIMALLOC=ON leaves the - # mi_* symbols unresolved in the shipped archives so Bun's own - # vendored mimalloc (oven-sh/mimalloc) satisfies them at link time. - - lto_flag: "" - label: bun-webkit-linux-amd64-mimalloc - os: linux-x64-gh - package_json_arch: "x64" - CMAKE_BUILD_TYPE: "Release" - RELEASE_FLAGS: "-O3 -DNDEBUG=1" - USE_MIMALLOC: "ON" - USE_EXTERNAL_MIMALLOC: "ON" - - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" - label: bun-webkit-linux-amd64-mimalloc-lto - os: linux-x64-gh - package_json_arch: "x64" - CMAKE_BUILD_TYPE: "Release" - RELEASE_FLAGS: "-O3 -DNDEBUG=1" - USE_MIMALLOC: "ON" - USE_EXTERNAL_MIMALLOC: "ON" - - lto_flag: "" - label: bun-webkit-linux-arm64-mimalloc - os: linux-arm64-gh - package_json_arch: "arm64" - CMAKE_BUILD_TYPE: "Release" - RELEASE_FLAGS: "-O3 -DNDEBUG=1" - USE_MIMALLOC: "ON" - USE_EXTERNAL_MIMALLOC: "ON" - - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" - label: bun-webkit-linux-arm64-mimalloc-lto - os: linux-arm64-gh - package_json_arch: "arm64" - CMAKE_BUILD_TYPE: "Release" - RELEASE_FLAGS: "-O3 -DNDEBUG=1" - USE_MIMALLOC: "ON" - USE_EXTERNAL_MIMALLOC: "ON" timeout-minutes: 90 steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 @@ -204,6 +180,8 @@ jobs: package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" lto_flag: "" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-windows-amd64-lto win_arch: x64 package_json_arch: "x64" @@ -219,6 +197,8 @@ jobs: # LTO codegen aborts ("Associative COMDAT symbol '??_7...' does # not exist"). lto_flag: "/clang:-flto=thin /clang:-fno-split-lto-unit" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-windows-amd64-debug win_arch: x64 package_json_arch: "x64" @@ -230,6 +210,8 @@ jobs: CMAKE_BUILD_TYPE: "Release" lto_flag: "" baseline: "true" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-windows-amd64-baseline-lto win_arch: x64 package_json_arch: "x64" @@ -240,6 +222,8 @@ jobs: # LTO too — matching bun-webkit-linux-amd64-baseline-lto. lto_flag: "/clang:-flto=thin /clang:-fno-split-lto-unit" baseline: "true" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" # ASAN is x64-only: LLVM ships no Windows ARM64 ASAN runtime. The # sanitizer runtime (import lib, /MT runtime thunk, DLL) comes from # the compiler-rt-windows-* release tag (see Dockerfile.windows). @@ -254,6 +238,8 @@ jobs: package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" lto_flag: "" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" # No arm64-lto variant: LLVM 21's CodeView emitter has no register # mapping for ARM64 NEON quad-register tuples ("LLVM ERROR: unknown # codeview register Q22_Q23_Q24_Q25") and the LTO codegen allocates @@ -278,7 +264,7 @@ jobs: - name: Run run: | rm -rf ${{runner.temp}}/bun-webkit ${{runner.temp}}/bun-webkit.tar.gz - WIN_ARCH="${{matrix.win_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" LTO_FLAG="${{matrix.lto_flag}}" BASELINE="${{matrix.baseline}}" ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" temp=${{runner.temp}} bash windows-cross-release.sh + WIN_ARCH="${{matrix.win_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" LTO_FLAG="${{matrix.lto_flag}}" BASELINE="${{matrix.baseline}}" ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" temp=${{runner.temp}} bash windows-cross-release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["windows"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -375,33 +361,45 @@ jobs: os: linux-arm64-gh package_json_arch: "arm64" CMAKE_BUILD_TYPE: "MinSizeRel" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-arm64-musl os: linux-arm64-gh package_json_arch: "arm64" CMAKE_BUILD_TYPE: "MinSizeRel" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" label: bun-webkit-linux-amd64-musl-lto os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "MinSizeRel" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-amd64-musl os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "MinSizeRel" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "-flto=full -fwhole-program-vtables -fforce-emit-vtables" label: bun-webkit-linux-amd64-musl-baseline-lto os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "MinSizeRel" MARCH_FLAG: "-march=nehalem" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - lto_flag: "" label: bun-webkit-linux-amd64-musl-baseline os: linux-x64-gh package_json_arch: "x64" CMAKE_BUILD_TYPE: "MinSizeRel" MARCH_FLAG: "-march=nehalem" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" timeout-minutes: 90 steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 @@ -424,7 +422,7 @@ jobs: else export MARCH_FLAG="${{ matrix.MARCH_FLAG || '-march=haswell' }}" fi - WEBKIT_RELEASE_TYPE=${{matrix.CMAKE_BUILD_TYPE}} CPU="native" cpu=native LTO_FLAG="${{matrix.lto_flag}}" temp=${{runner.temp}} bash musl-release.sh + WEBKIT_RELEASE_TYPE=${{matrix.CMAKE_BUILD_TYPE}} CPU="native" cpu=native LTO_FLAG="${{matrix.lto_flag}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" temp=${{runner.temp}} bash musl-release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["linux"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -454,11 +452,15 @@ jobs: package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" lto_flag: "" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-macos-arm64-lto macos_arch: arm64 package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" lto_flag: "-flto=thin -fno-split-lto-unit -fwhole-program-vtables -fforce-emit-vtables" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-macos-arm64-debug macos_arch: arm64 package_json_arch: "arm64" @@ -470,11 +472,15 @@ jobs: package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" lto_flag: "" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-macos-amd64-lto macos_arch: x86_64 package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" lto_flag: "-flto=thin -fno-split-lto-unit -fwhole-program-vtables -fforce-emit-vtables" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-macos-amd64-debug macos_arch: x86_64 package_json_arch: "x64" @@ -516,7 +522,7 @@ jobs: - name: Run run: | rm -rf ${{runner.temp}}/bun-webkit ${{runner.temp}}/bun-webkit.tar.gz - MACOS_ARCH="${{matrix.macos_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" LTO_FLAG="${{matrix.lto_flag}}" CPP_FLAGS="${{matrix.cpp_flags}}" ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" ENABLE_MALLOC_HEAP_BREAKDOWN="${{matrix.ENABLE_MALLOC_HEAP_BREAKDOWN}}" temp=${{runner.temp}} bash macos-cross-release.sh + MACOS_ARCH="${{matrix.macos_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" LTO_FLAG="${{matrix.lto_flag}}" CPP_FLAGS="${{matrix.cpp_flags}}" ENABLE_SANITIZERS="${{matrix.ENABLE_SANITIZERS}}" ENABLE_MALLOC_HEAP_BREAKDOWN="${{matrix.ENABLE_MALLOC_HEAP_BREAKDOWN}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" temp=${{runner.temp}} bash macos-cross-release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["darwin"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -539,6 +545,8 @@ jobs: freebsd_arch: x86_64 package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-freebsd-amd64-debug freebsd_arch: x86_64 package_json_arch: "x64" @@ -547,6 +555,8 @@ jobs: freebsd_arch: aarch64 package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-freebsd-arm64-debug freebsd_arch: aarch64 package_json_arch: "arm64" @@ -568,7 +578,7 @@ jobs: - name: Run run: | rm -rf ${{runner.temp}}/bun-webkit ${{runner.temp}}/bun-webkit.tar.gz - FREEBSD_ARCH="${{matrix.freebsd_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" temp=${{runner.temp}} bash freebsd-release.sh + FREEBSD_ARCH="${{matrix.freebsd_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" temp=${{runner.temp}} bash freebsd-release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["freebsd"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -592,6 +602,8 @@ jobs: android_arch: aarch64 package_json_arch: "arm64" CMAKE_BUILD_TYPE: "Release" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-linux-arm64-android-debug android_arch: aarch64 package_json_arch: "arm64" @@ -600,6 +612,8 @@ jobs: android_arch: x86_64 package_json_arch: "x64" CMAKE_BUILD_TYPE: "Release" + USE_MIMALLOC: "ON" + USE_EXTERNAL_MIMALLOC: "ON" - label: bun-webkit-linux-amd64-android-debug android_arch: x86_64 package_json_arch: "x64" @@ -621,7 +635,7 @@ jobs: - name: Run run: | rm -rf ${{runner.temp}}/bun-webkit ${{runner.temp}}/bun-webkit.tar.gz - ANDROID_ARCH="${{matrix.android_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" temp=${{runner.temp}} bash android-release.sh + ANDROID_ARCH="${{matrix.android_arch}}" WEBKIT_RELEASE_TYPE="${{matrix.CMAKE_BUILD_TYPE}}" USE_MIMALLOC="${{matrix.USE_MIMALLOC || 'OFF'}}" USE_EXTERNAL_MIMALLOC="${{matrix.USE_EXTERNAL_MIMALLOC || 'OFF'}}" temp=${{runner.temp}} bash android-release.sh cd ${{runner.temp}} echo "#define BUN_WEBKIT_VERSION \"${{ inputs.build_ref }}\"" >> bun-webkit/include/cmakeconfig.h echo '{ "name": "${{matrix.label}}", "version": "0.0.1-${{ inputs.build_ref }}", "os": ["android"], "cpu": ["${{matrix.package_json_arch}}"], "repository": "https://github.com/${{github.repository}}" }' > bun-webkit/package.json @@ -732,22 +746,6 @@ jobs: with: name: bun-webkit-linux-arm64-lto path: ${{runner.temp}}/bun-webkit-linux-arm64-lto - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: bun-webkit-linux-amd64-mimalloc - path: ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: bun-webkit-linux-amd64-mimalloc-lto - path: ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc-lto - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: bun-webkit-linux-arm64-mimalloc - path: ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: bun-webkit-linux-arm64-mimalloc-lto - path: ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc-lto - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: bun-webkit-linux-amd64-baseline @@ -874,10 +872,6 @@ jobs: mv ${{runner.temp}}/bun-webkit-macos-amd64-debug/bun-webkit.tar.gz ./out/bun-webkit-macos-amd64-debug.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-arm64-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-lto.tar.gz - mv ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-mimalloc.tar.gz - mv ${{runner.temp}}/bun-webkit-linux-amd64-mimalloc-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-mimalloc-lto.tar.gz - mv ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-mimalloc.tar.gz - mv ${{runner.temp}}/bun-webkit-linux-arm64-mimalloc-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-mimalloc-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-baseline/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-baseline.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-baseline-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-baseline-lto.tar.gz mv ${{runner.temp}}/bun-webkit-linux-amd64-musl-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-amd64-musl-lto.tar.gz @@ -928,10 +922,6 @@ jobs: ./out/bun-webkit-linux-arm64-debug.tar.gz ./out/bun-webkit-linux-amd64-debug-asan.tar.gz ./out/bun-webkit-linux-arm64-debug-asan.tar.gz - ./out/bun-webkit-linux-amd64-mimalloc.tar.gz - ./out/bun-webkit-linux-amd64-mimalloc-lto.tar.gz - ./out/bun-webkit-linux-arm64-mimalloc.tar.gz - ./out/bun-webkit-linux-arm64-mimalloc-lto.tar.gz - uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15 with: diff --git a/Dockerfile.android b/Dockerfile.android index 3865c0141365c..eb40d67bc02b6 100644 --- a/Dockerfile.android +++ b/Dockerfile.android @@ -7,6 +7,8 @@ ARG NDK_SHA256="59c2f6dc96743b5daf5d1626684640b20a6bd2b1d85b13156b90333741bad5cc ARG ANDROID_API="28" ARG ANDROID_ARCH="aarch64" ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -g -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 " +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" ARG ICU_VERSION="75_1" ARG ICU_RELEASE_TAG="release-75-1" ARG ICU_SHA256="cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef" @@ -141,6 +143,8 @@ ARG LTO_FLAG ARG DEFAULT_CFLAGS ARG ANDROID_API ARG ANDROID_ARCH +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC COPY . /webkit WORKDIR /webkit @@ -175,6 +179,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DUSE_THIN_ARCHIVES=OFF \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DUSE_BUN_EVENT_LOOP=ON \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -DENABLE_FTL_JIT=ON \ -DENABLE_API_TESTS=OFF \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ diff --git a/Dockerfile.freebsd b/Dockerfile.freebsd index 6670f864f1152..7b160d182ad44 100644 --- a/Dockerfile.freebsd +++ b/Dockerfile.freebsd @@ -5,6 +5,8 @@ ARG LLVM_VERSION="21" ARG FREEBSD_VERSION="14.3" ARG FREEBSD_ARCH="x86_64" ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 " +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" # -g is added per-stage below for Debug only — with -O3 + tmpfs, debug info # OOMs the linux-x64-gh runner during Release builds (not seen on Android, # but FreeBSD's libc++ headers generate notably more DWARF). @@ -131,6 +133,8 @@ ARG LTO_FLAG ARG DEFAULT_CFLAGS ARG FREEBSD_VERSION ARG FREEBSD_ARCH +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC COPY . /webkit WORKDIR /webkit @@ -161,6 +165,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DUSE_THIN_ARCHIVES=OFF \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DUSE_BUN_EVENT_LOOP=ON \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -DENABLE_FTL_JIT=ON \ -DENABLE_API_TESTS=OFF \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ diff --git a/Dockerfile.macos b/Dockerfile.macos index 0b9a56c0023f9..04daeabdc8679 100644 --- a/Dockerfile.macos +++ b/Dockerfile.macos @@ -45,6 +45,8 @@ ARG ENABLE_MALLOC_HEAP_BREAKDOWN="OFF" # official LLVM macOS release is arm64-only), so x86_64 ASAN variants would # fail to link. ARG ENABLE_SANITIZERS="" +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" ARG COMPILER_RT_DARWIN_TAG="compiler-rt-darwin-21.1.8" ARG COMPILER_RT_DARWIN_SHA256="f9bab8191d63873682ec69492d06cfdf0807a7335c4e9b188ef013b3cc3c9dbc" @@ -164,6 +166,8 @@ ARG DEFAULT_CFLAGS ARG CPP_FLAGS ARG ENABLE_MALLOC_HEAP_BREAKDOWN ARG ENABLE_SANITIZERS +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC COPY --from=build_mig /usr/local/bin/mig /usr/local/bin/migcom /usr/local/bin/ COPY . /webkit @@ -201,6 +205,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DUSE_THIN_ARCHIVES=OFF \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DUSE_BUN_EVENT_LOOP=ON \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -DENABLE_FTL_JIT=ON \ -DENABLE_API_TESTS=OFF \ -DENABLE_MALLOC_HEAP_BREAKDOWN=${ENABLE_MALLOC_HEAP_BREAKDOWN} \ diff --git a/Dockerfile.musl b/Dockerfile.musl index 8cdc5408f19cd..4a92abc0d89e1 100644 --- a/Dockerfile.musl +++ b/Dockerfile.musl @@ -4,6 +4,8 @@ ARG CPU=native ARG LTO_FLAG="-flto=full -fwhole-program-vtables -fforce-emit-vtables " ARG LLVM_VERSION="21" ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -g -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 " +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" FROM alpine:3.23 as base @@ -95,6 +97,8 @@ ARG CPU ARG LTO_FLAG ARG LLVM_VERSION ARG DEFAULT_CFLAGS +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC RUN apk add --no-cache cpio curl file gnupg ninja ruby ruby-getoptlong unzip rsync perl python3 openssl-dev openssl linux-headers @@ -120,6 +124,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DUSE_THIN_ARCHIVES=OFF \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DUSE_BUN_EVENT_LOOP=ON \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -DENABLE_FTL_JIT=ON \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \ diff --git a/Dockerfile.windows b/Dockerfile.windows index a75374c4aeec7..b73f5c404cc03 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -32,6 +32,8 @@ ARG ICU_MARCH_FLAG="-march=haswell" # "address,undefined" for the -asan variant. x64 only: LLVM does not ship a # Windows ARM64 ASAN runtime. ARG ENABLE_SANITIZERS="" +ARG USE_MIMALLOC="OFF" +ARG USE_EXTERNAL_MIMALLOC="OFF" ARG LLVM_VERSION="21" ARG XWIN_VERSION="0.9.0" ARG XWIN_SHA256="31e1033f30608ba6b821d17f1461042bd54c23424813c9b4e9ae15b6d32fa4cd" @@ -299,6 +301,8 @@ ARG WEBKIT_RELEASE_TYPE ARG LTO_FLAG ARG MARCH_FLAG ARG ENABLE_SANITIZERS +ARG USE_MIMALLOC +ARG USE_EXTERNAL_MIMALLOC COPY --from=build_icu /icu-out /icu-out COPY . /webkit @@ -366,6 +370,8 @@ RUN --mount=type=tmpfs,target=/webkitbuild \ -DENABLE_WEBASSEMBLY=ON \ -DUSE_BUN_JSC_ADDITIONS=ON \ -DUSE_BUN_EVENT_LOOP=ON \ + -DUSE_MIMALLOC="$USE_MIMALLOC" \ + -DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ -DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON \ -DENABLE_REMOTE_INSPECTOR=ON \ -DENABLE_SANITIZERS="${ENABLE_SANITIZERS}" \ diff --git a/android-release.sh b/android-release.sh index 2865615f9f0d9..f639ca4bc537a 100755 --- a/android-release.sh +++ b/android-release.sh @@ -11,6 +11,8 @@ export ANDROID_ARCH="${ANDROID_ARCH:-aarch64}" export ANDROID_API="${ANDROID_API:-28}" export WEBKIT_RELEASE_TYPE="${WEBKIT_RELEASE_TYPE:-Release}" export LTO_FLAG="${LTO_FLAG:-}" +export USE_MIMALLOC="${USE_MIMALLOC:-OFF}" +export USE_EXTERNAL_MIMALLOC="${USE_EXTERNAL_MIMALLOC:-OFF}" case "$ANDROID_ARCH" in aarch64) : "${MARCH_FLAG:="-march=armv8-a+crc -mtune=cortex-a78"}" ;; @@ -34,6 +36,8 @@ docker buildx build -f Dockerfile.android -t "$CONTAINER_NAME" \ --build-arg LTO_FLAG="$LTO_FLAG" \ --build-arg MARCH_FLAG="$MARCH_FLAG" \ --build-arg WEBKIT_RELEASE_TYPE="$WEBKIT_RELEASE_TYPE" \ + --build-arg USE_MIMALLOC="$USE_MIMALLOC" \ + --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ --progress=plain \ --platform=linux/amd64 \ --target=artifact \ diff --git a/freebsd-release.sh b/freebsd-release.sh index b1933bd8d1361..591f3338a8369 100755 --- a/freebsd-release.sh +++ b/freebsd-release.sh @@ -10,6 +10,8 @@ export FREEBSD_ARCH="${FREEBSD_ARCH:-x86_64}" export FREEBSD_VERSION="${FREEBSD_VERSION:-14.3}" export WEBKIT_RELEASE_TYPE="${WEBKIT_RELEASE_TYPE:-Release}" export LTO_FLAG="${LTO_FLAG:-}" +export USE_MIMALLOC="${USE_MIMALLOC:-OFF}" +export USE_EXTERNAL_MIMALLOC="${USE_EXTERNAL_MIMALLOC:-OFF}" case "$FREEBSD_ARCH" in x86_64) : "${MARCH_FLAG:="-march=haswell"}" ;; @@ -33,6 +35,8 @@ docker buildx build -f Dockerfile.freebsd -t "$CONTAINER_NAME" \ --build-arg LTO_FLAG="$LTO_FLAG" \ --build-arg MARCH_FLAG="$MARCH_FLAG" \ --build-arg WEBKIT_RELEASE_TYPE="$WEBKIT_RELEASE_TYPE" \ + --build-arg USE_MIMALLOC="$USE_MIMALLOC" \ + --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ --progress=plain \ --platform=linux/amd64 \ --target=artifact \ diff --git a/macos-cross-release.sh b/macos-cross-release.sh index c7b28b8d536f6..b698d0811eaa6 100755 --- a/macos-cross-release.sh +++ b/macos-cross-release.sh @@ -12,6 +12,8 @@ export WEBKIT_RELEASE_TYPE="${WEBKIT_RELEASE_TYPE:-Release}" export LTO_FLAG="${LTO_FLAG:-}" export CPP_FLAGS="${CPP_FLAGS:-}" export ENABLE_SANITIZERS="${ENABLE_SANITIZERS:-}" +export USE_MIMALLOC="${USE_MIMALLOC:-OFF}" +export USE_EXTERNAL_MIMALLOC="${USE_EXTERNAL_MIMALLOC:-OFF}" # Match the native macOS lanes: apple-m1 on the arm64 runners (`cpu: native` # on macos-14-xlarge), haswell on the amd64 ones. @@ -48,6 +50,8 @@ docker buildx build -f Dockerfile.macos -t "$CONTAINER_NAME" \ --build-arg WEBKIT_RELEASE_TYPE="$WEBKIT_RELEASE_TYPE" \ --build-arg ENABLE_MALLOC_HEAP_BREAKDOWN="$ENABLE_MALLOC_HEAP_BREAKDOWN" \ --build-arg ENABLE_SANITIZERS="$ENABLE_SANITIZERS" \ + --build-arg USE_MIMALLOC="$USE_MIMALLOC" \ + --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ --progress=plain \ --platform=linux/amd64 \ --target=artifact \ diff --git a/musl-release.sh b/musl-release.sh index 16236205c241b..a9a72fcf711ca 100644 --- a/musl-release.sh +++ b/musl-release.sh @@ -50,7 +50,10 @@ if [ "$WEBKIT_RELEASE_TYPE" == "relwithdebuginfo" ]; then CONTAINER_NAME=bun-webkit-linux-$BUILDKIT_ARCH-dbg fi +export USE_MIMALLOC=${USE_MIMALLOC:-"OFF"} +export USE_EXTERNAL_MIMALLOC=${USE_EXTERNAL_MIMALLOC:-"OFF"} + mkdir -p $temp rm -rf $temp/bun-webkit -docker buildx build -f Dockerfile.musl -t $CONTAINER_NAME --build-arg LTO_FLAG="$LTO_FLAG" --build-arg MARCH_FLAG="$MARCH_FLAG" --build-arg WEBKIT_RELEASE_TYPE=$WEBKIT_RELEASE_TYPE --progress=plain --platform=linux/$BUILDKIT_ARCH --target=artifact --output type=local,dest=$temp/bun-webkit . +docker buildx build -f Dockerfile.musl -t $CONTAINER_NAME --build-arg LTO_FLAG="$LTO_FLAG" --build-arg MARCH_FLAG="$MARCH_FLAG" --build-arg WEBKIT_RELEASE_TYPE=$WEBKIT_RELEASE_TYPE --build-arg USE_MIMALLOC="$USE_MIMALLOC" --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" --progress=plain --platform=linux/$BUILDKIT_ARCH --target=artifact --output type=local,dest=$temp/bun-webkit . diff --git a/windows-cross-release.sh b/windows-cross-release.sh index 311c1b0934d94..54a0925141a3e 100755 --- a/windows-cross-release.sh +++ b/windows-cross-release.sh @@ -10,6 +10,8 @@ export WIN_ARCH="${WIN_ARCH:-x64}" export WEBKIT_RELEASE_TYPE="${WEBKIT_RELEASE_TYPE:-Release}" export LTO_FLAG="${LTO_FLAG:-}" export ENABLE_SANITIZERS="${ENABLE_SANITIZERS:-}" +export USE_MIMALLOC="${USE_MIMALLOC:-OFF}" +export USE_EXTERNAL_MIMALLOC="${USE_EXTERNAL_MIMALLOC:-OFF}" # Codegen floor per arch, matching windows-release.ps1: # x64 -> haswell, x64 baseline -> nehalem, arm64 -> armv8-a+crc. @@ -56,6 +58,8 @@ docker buildx build -f Dockerfile.windows -t "$CONTAINER_NAME" \ --build-arg MARCH_FLAG="$MARCH_FLAG" \ --build-arg ICU_MARCH_FLAG="$ICU_MARCH_FLAG" \ --build-arg ENABLE_SANITIZERS="$ENABLE_SANITIZERS" \ + --build-arg USE_MIMALLOC="$USE_MIMALLOC" \ + --build-arg USE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \ --progress=plain \ --platform=linux/amd64 \ --target=artifact \ From 4a486d101ead7d0e6ca5774b7fb0a116ae10b863 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 11:26:55 +0000 Subject: [PATCH 5/7] Revert Heap::didFinishCollection mi_collect hook The consumer's mimalloc now runs a demand-driven scavenger thread (woken from mi_arena_schedule_purge) that handles arena purge off the GC thread. The synchronous force-collect here costs ~13% on allocation- heavy workloads without further RSS benefit once the scavenger is present. --- Source/JavaScriptCore/heap/Heap.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index c3b1824cc9f3b..919148bf34c67 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -104,7 +104,6 @@ #include #include #include -#include #include #include #include @@ -2633,13 +2632,6 @@ void Heap::didFinishCollection() for (auto* observer : m_observers) observer->didGarbageCollect(scope); - -#if USE(MIMALLOC) - // libpas runs a scavenger thread; mimalloc only purges from alloc - // slow-paths, so drive it here after a full GC freed FastMalloc memory. - if (scope == CollectionScope::Full) - WTF::releaseFastMallocFreeMemoryForThisThread(); -#endif } void Heap::resumeCompilerThreads() From 342334e1176e118ac81136baa76ec3b0015efcdf Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 11:29:07 +0000 Subject: [PATCH 6/7] bmalloc: add force param to scavengeThisThread; call it force=false after full GC With the consumer's mimalloc scavenger thread handling arena madvise in the background, a force=true collect on the GC thread after every full GC is just synchronous cost (~13% on allocation-heavy workloads). force=false processes retired theap pages and schedules arena purges (waking the scavenger) without draining them inline. --- Source/JavaScriptCore/heap/Heap.cpp | 8 ++++++++ Source/bmalloc/bmalloc/bmalloc.cpp | 7 +++++-- Source/bmalloc/bmalloc/bmalloc.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index 919148bf34c67..10905dfe305c7 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -102,6 +102,7 @@ #include "WeakMapImplInlines.h" #include "WeakSetInlines.h" #include +#include #include #include #include @@ -2632,6 +2633,13 @@ void Heap::didFinishCollection() for (auto* observer : m_observers) observer->didGarbageCollect(scope); + +#if USE(MIMALLOC) + // Process retired theap pages and queue arena purges; the consumer's + // mimalloc scavenger thread does the actual madvise off the GC thread. + if (scope == CollectionScope::Full) + bmalloc::api::scavengeThisThread(/* force */ false); +#endif } void Heap::resumeCompilerThreads() diff --git a/Source/bmalloc/bmalloc/bmalloc.cpp b/Source/bmalloc/bmalloc/bmalloc.cpp index 6b5f3b6ed4423..02d1694849d29 100644 --- a/Source/bmalloc/bmalloc/bmalloc.cpp +++ b/Source/bmalloc/bmalloc/bmalloc.cpp @@ -112,13 +112,16 @@ void freeLargeVirtual(void* object, size_t size, HeapKind kind) #endif } -void scavengeThisThread() +void scavengeThisThread(bool force) { #if BENABLE(LIBPAS) + BUNUSED(force); pas_thread_local_cache_shrink(pas_thread_local_cache_try_get(), pas_lock_is_not_held); #elif BUSE(MIMALLOC) - mi_theap_collect(mi_theap_get_default(), /* force */ true); + mi_theap_collect(mi_theap_get_default(), force); +#else + BUNUSED(force); #endif } diff --git a/Source/bmalloc/bmalloc/bmalloc.h b/Source/bmalloc/bmalloc/bmalloc.h index b125f5dbe4a78..6e4a7ea21f17b 100644 --- a/Source/bmalloc/bmalloc/bmalloc.h +++ b/Source/bmalloc/bmalloc/bmalloc.h @@ -296,7 +296,7 @@ BEXPORT void freeOutOfLine(void* object, HeapKind kind = HeapKind::Primary); BEXPORT void freeLargeVirtual(void* object, size_t, HeapKind kind = HeapKind::Primary); -BEXPORT void scavengeThisThread(); +BEXPORT void scavengeThisThread(bool force = true); BEXPORT void scavenge(); From 24c63e7ddda0655b5d66518a6dfcadfcce8fc9ff Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 12 Jul 2026 23:54:58 +0000 Subject: [PATCH 7/7] StructureAlignedMemoryAllocator: re-inherit the structure heap on macOS too tryReserveUncommittedAligned maps this region with mach_vm_map(..., VM_INHERIT_NONE) on Darwin, so the same fork-child walk into mimalloc's in-region mi_arena_t/theap structs applies there. Restore VM_INHERIT_COPY after registering the region with mimalloc, mirroring the Linux MADV_DOFORK branch. Also reword the USE_EXTERNAL_MIMALLOC help string from "Implies" to "Requires" to match WEBKIT_OPTION_DEPEND's actual semantics. --- .../JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp | 6 ++++++ Source/cmake/WebKitFeatures.cmake | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp index 3057877e03c69..f1737c24c7d86 100644 --- a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp +++ b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp @@ -51,6 +51,8 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN #if OS(LINUX) #include #include +#elif OS(DARWIN) +#include #endif #endif WTF_ALLOW_UNSAFE_BUFFER_USAGE_END @@ -149,6 +151,10 @@ class StructureMemoryManager { // mi_arena_t and theaps inside this region and registers them in // process-wide lists that _mi_process_fork_child walks pre-exec. while (madvise(reinterpret_cast(g_jscConfig.startOfStructureHeap), g_jscConfig.sizeOfStructureHeap, MADV_DOFORK) == -1 && errno == EAGAIN) { } +#elif OS(DARWIN) + // Undo tryReserveUncommittedAligned's mach_vm_map(..., VM_INHERIT_NONE); + // same rationale as the Linux MADV_DOFORK branch above. + vm_inherit(mach_task_self(), static_cast(g_jscConfig.startOfStructureHeap), static_cast(g_jscConfig.sizeOfStructureHeap), VM_INHERIT_COPY); #endif return; } diff --git a/Source/cmake/WebKitFeatures.cmake b/Source/cmake/WebKitFeatures.cmake index d949d65684023..d2af4a74e06c4 100644 --- a/Source/cmake/WebKitFeatures.cmake +++ b/Source/cmake/WebKitFeatures.cmake @@ -308,7 +308,7 @@ macro(WEBKIT_OPTION_BEGIN) WEBKIT_OPTION_DEFINE(USE_SKIA_ENCODERS "Whether to use Skia image encoders" PRIVATE ON) WEBKIT_OPTION_DEFINE(USE_SYSTEM_MALLOC "Toggle system allocator instead of WebKit's custom allocator" PRIVATE ${USE_SYSTEM_MALLOC_DEFAULT}) WEBKIT_OPTION_DEFINE(USE_MIMALLOC "Toggle mimalloc instead of WebKit's custom allocator" PRIVATE ${USE_MIMALLOC_DEFAULT}) - WEBKIT_OPTION_DEFINE(USE_EXTERNAL_MIMALLOC "Compile against mimalloc headers but leave mi_* symbols unresolved in the static archives (caller links its own mimalloc). Implies USE_MIMALLOC." PRIVATE OFF) + WEBKIT_OPTION_DEFINE(USE_EXTERNAL_MIMALLOC "Compile against mimalloc headers but leave mi_* symbols unresolved in the static archives (caller links its own mimalloc). Requires USE_MIMALLOC." PRIVATE OFF) WEBKIT_OPTION_DEFINE(USE_PGO_PROFILE "Use PGO profile data for optimization (set PGO_PROFILE_PATH)" PRIVATE OFF) WEBKIT_OPTION_DEFINE(USE_WOFF2 "Toggle support for WOFF2 Web Fonts through libwoff2" PRIVATE ON)