Skip to content

Commit c89442d

Browse files
authored
Add the mimalloc option to speed up the compiler on Windows (#831)
1 parent ed56305 commit c89442d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
libxml2_revision: ${{ steps.context.outputs.libxml2_revision }}
104104
libxml2_version: ${{ steps.context.outputs.libxml2_version }}
105105
llvm_project_revision: ${{ steps.context.outputs.llvm_project_revision }}
106+
mimalloc_revision: ${{ steps.context.outputs.mimalloc_revision }}
106107
sourcekit_lsp_revision: ${{ steps.context.outputs.sourcekit_lsp_revision }}
107108
swift_argument_parser_revision: ${{ steps.context.outputs.swift_argument_parser_revision }}
108109
swift_asn1_revision: ${{ steps.context.outputs.swift_asn1_revision }}
@@ -183,6 +184,7 @@ jobs:
183184
tee -a "${GITHUB_OUTPUT}" <<-EOF
184185
indexstore_db_revision=refs/tags/${{ inputs.swift_tag }}
185186
llvm_project_revision=refs/tags/${{ inputs.swift_tag }}
187+
mimalloc_revision=refs/tags/v2.1.7
186188
sourcekit_lsp_revision=refs/tags/${{ inputs.swift_tag }}
187189
swift_revision=refs/tags/${{ inputs.swift_tag }}
188190
swift_argument_parser_revision=refs/tags/1.4.0
@@ -480,6 +482,7 @@ jobs:
480482
libxml2_revision: ${{ needs.context.outputs.libxml2_revision }}
481483
libxml2_version: ${{ needs.context.outputs.libxml2_version }}
482484
llvm_project_revision: ${{ needs.context.outputs.llvm_project_revision }}
485+
mimalloc_revision: ${{ needs.context.outputs.mimalloc_revision }}
483486
sourcekit_lsp_revision: ${{ needs.context.outputs.sourcekit_lsp_revision }}
484487
swift_argument_parser_revision: ${{ needs.context.outputs.swift_argument_parser_revision }}
485488
swift_asn1_revision: ${{ needs.context.outputs.swift_asn1_revision }}
@@ -552,6 +555,7 @@ jobs:
552555
libxml2_revision: ${{ needs.context.outputs.libxml2_revision }}
553556
libxml2_version: ${{ needs.context.outputs.libxml2_version }}
554557
llvm_project_revision: ${{ needs.context.outputs.llvm_project_revision }}
558+
mimalloc_revision: ${{ needs.context.outputs.mimalloc_revision }}
555559
sourcekit_lsp_revision: ${{ needs.context.outputs.sourcekit_lsp_revision }}
556560
swift_argument_parser_revision: ${{ needs.context.outputs.swift_argument_parser_revision }}
557561
swift_asn1_revision: ${{ needs.context.outputs.swift_asn1_revision }}

.github/workflows/swift-toolchain.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ on:
5151
required: true
5252
type: string
5353

54+
mimalloc_revision:
55+
required: true
56+
type: string
57+
5458
sourcekit_lsp_revision:
5559
required: true
5660
type: string
@@ -3193,6 +3197,41 @@ jobs:
31933197
Install-Package -Name WixToolset.Sdk -RequiredVersion 4.0.1 -Force
31943198
}
31953199
3200+
- uses: actions/checkout@v4
3201+
if: matrix.arch == 'amd64'
3202+
with:
3203+
repository: microsoft/mimalloc
3204+
ref: ${{ inputs.mimalloc_revision }}
3205+
path: ${{ github.workspace }}/SourceCache/mimalloc
3206+
3207+
- name: Build and apply mimalloc
3208+
if: matrix.arch == 'amd64'
3209+
run: |
3210+
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
3211+
msbuild ${{ github.workspace }}\SourceCache\mimalloc\ide\vs2022\mimalloc.sln -p:Configuration=Release
3212+
$ToolchainBin = "${{ github.workspace }}\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
3213+
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-override.dll" `
3214+
-Destination "$ToolchainBin"
3215+
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-redirect.dll" `
3216+
-Destination "$ToolchainBin"
3217+
$MimallocExecutables = @("swift.exe",
3218+
"swiftc.exe",
3219+
"swift-driver.exe",
3220+
"swift-frontend.exe",
3221+
"clang.exe",
3222+
"clang++.exe",
3223+
"clang-cl.exe",
3224+
"lld.exe",
3225+
"lld-link.exe",
3226+
"ld.lld.exe",
3227+
"ld64.lld.exe")
3228+
foreach ($Exe in $MimallocExecutables) {
3229+
# Binary-patch in place
3230+
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -f -i -v "$ToolchainBin\$Exe"
3231+
# Log the import table
3232+
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -l "$ToolchainBin\$Exe"
3233+
}
3234+
31963235
- name: Package Build Tools
31973236
run: |
31983237
msbuild -nologo -restore -maxCpuCount `
@@ -3203,6 +3242,7 @@ jobs:
32033242
-p:PASSPHRASE=${{ secrets.PASSPHRASE }} `
32043243
-p:DEVTOOLS_ROOT=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain `
32053244
-p:TOOLCHAIN_ROOT=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain `
3245+
-p:ENABLE_MIMALLOC=true `
32063246
-p:ProductArchitecture=${{ matrix.arch }} `
32073247
-p:ProductVersion=${{ inputs.swift_version }} `
32083248
${{ github.workspace }}/SourceCache/swift-installer-scripts/platforms/Windows/bld/bld.wixproj

default.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,7 @@
6363

6464
<project remote="github" name="madler/zlib" path="zlib" revision="refs/tags/v1.3.1" />
6565

66+
<project remote="github" name="microsoft/mimalloc" path="mimalloc" revision="refs/tags/v2.1.7" />
67+
6668
<project remote="github" name="ninja-build/ninja" path="ninja" groups="notdefault,dependencies" revision="master" />
6769
</manifest>

0 commit comments

Comments
 (0)