Introduce mimalloc to static Linux binaries (#6321)

mimalloc is performant memory allocator written in C that works as drop-in replacement for malloc and supports builds for musl. Compared with other popular allocators like jemalloc or tcmalloc, it's a fair option. 

https://github.com/microsoft/mimalloc

Also, in the Swift compiler project (swiftlang/swift), mimaloc has been adopted as the allocator in Windows's toolchain (not runtime!):

https://forums.swift.org/t/se-454-adopt-mimalloc-for-windows-toolchain/

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
This commit is contained in:
Satoshi Namai
2025-10-28 09:26:22 +00:00
committed by GitHub
parent 8c4ef0de7e
commit 8ee8523246
3 changed files with 32 additions and 5 deletions
+24 -2
View File
@@ -15,6 +15,7 @@ on:
env:
DEVELOPER_DIR: /Applications/Xcode_26.0.1.app
RELEASE_BRANCH: release/${{ inputs.version }}
MIMALLOC_VERSION: 3.0.10
jobs:
setup-credentials:
@@ -144,21 +145,39 @@ jobs:
persist-credentials: false
- name: Install SDK
run: swift sdk install https://download.swift.org/swift-6.2-release/static-sdk/swift-6.2-RELEASE/swift-6.2-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum d2225840e592389ca517bbf71652f7003dbf45ac35d1e57d98b9250368769378
- name: Build mimalloc object
run: |
set -euxo pipefail
curl -sSfL "https://github.com/microsoft/mimalloc/archive/refs/tags/v${MIMALLOC_VERSION}.tar.gz" | tar xz
export CC=clang
cmake -S "mimalloc-${MIMALLOC_VERSION}" -B mimalloc-build \
-DMI_BUILD_SHARED=OFF \
-DMI_BUILD_STATIC=ON \
-DMI_BUILD_OBJECT=OFF \
-DCMAKE_BUILD_TYPE=Release
cmake --build mimalloc-build --target mimalloc-static
- name: Build static binary
run: |
# To improve performance with musl, increase the stack size to 512KiB and
# replace musl's default allocator with mimalloc.
swift build \
-c release \
--product swiftlint \
--swift-sdk ${{ matrix.swift_sdk }} \
-Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT \
-Xlinker -z -Xlinker stack-size=0x80000 # 512KiB
-Xlinker -z -Xlinker stack-size=0x80000 \
-Xlinker --whole-archive \
-Xlinker ./mimalloc-build/libmimalloc.a \
-Xlinker --no-whole-archive
- name: Strip binary
run: strip -s "$BINARY_PATH"
- name: Upload artifact
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: ${{ matrix.artifact_name }}
path: ${{ env.BINARY_PATH }}
path: |
${{ env.BINARY_PATH }}
mimalloc-build/LICENSE
build-macos:
name: Build macOS Binaries
@@ -214,6 +233,9 @@ jobs:
mv -f swiftlint-linux-arm64/swiftlint swiftlint_linux_arm64
mv -f swiftlint-static-amd64/swiftlint swiftlint_static_amd64
mv -f swiftlint-static-arm64/swiftlint swiftlint_static_arm64
# Just pick one of the licenses.
mv -f swiftlint-static-amd64/LICENSE LICENSE.mimalloc
- name: Make binaries executable
run: chmod +x swiftlint*
- name: Create artifacts
+5
View File
@@ -29,6 +29,11 @@
[nandhinisubbu](https://github.com/nandhinisubbu)
[#6161](https://github.com/realm/SwiftLint/issues/6161)
* Adopt [mimalloc](https://github.com/microsoft/mimalloc) for static Linux binary
to improve performance.
[ainame](https://github.com/ainame)
[#6298](https://github.com/realm/SwiftLint/issues/6298)
### Bug Fixes
* Fix false positive with `#Preview` macro in `closure_end_indentation` rule.
+3 -3
View File
@@ -119,11 +119,11 @@ zip_linux_release: swiftlint_linux_amd64 swiftlint_linux_arm64 swiftlint_static_
$(eval TMP_FOLDER := $(shell mktemp -d))
cp -f swiftlint_linux_amd64 "$(TMP_FOLDER)/swiftlint"
cp -f swiftlint_static_amd64 "$(TMP_FOLDER)/swiftlint-static"
cp -f LICENSE "$(TMP_FOLDER)"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint-static" "LICENSE") > "./swiftlint_linux_amd64.zip"
cp -f LICENSE LICENSE.mimalloc "$(TMP_FOLDER)"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint-static" "LICENSE" "LICENSE.mimalloc") > "./swiftlint_linux_amd64.zip"
cp -f swiftlint_linux_arm64 "$(TMP_FOLDER)/swiftlint"
cp -f swiftlint_static_arm64 "$(TMP_FOLDER)/swiftlint-static"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint-static" "LICENSE") > "./swiftlint_linux_arm64.zip"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint-static" "LICENSE" "LICENSE.mimalloc") > "./swiftlint_linux_arm64.zip"
package: swiftlint
$(eval PACKAGE_ROOT := $(shell mktemp -d))