Skip to content

Commit

Permalink
Add the mimalloc option to speed up the compiler on Windows (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjyamauchi authored Sep 23, 2024
1 parent ed56305 commit c89442d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
libxml2_revision: ${{ steps.context.outputs.libxml2_revision }}
libxml2_version: ${{ steps.context.outputs.libxml2_version }}
llvm_project_revision: ${{ steps.context.outputs.llvm_project_revision }}
mimalloc_revision: ${{ steps.context.outputs.mimalloc_revision }}
sourcekit_lsp_revision: ${{ steps.context.outputs.sourcekit_lsp_revision }}
swift_argument_parser_revision: ${{ steps.context.outputs.swift_argument_parser_revision }}
swift_asn1_revision: ${{ steps.context.outputs.swift_asn1_revision }}
Expand Down Expand Up @@ -183,6 +184,7 @@ jobs:
tee -a "${GITHUB_OUTPUT}" <<-EOF
indexstore_db_revision=refs/tags/${{ inputs.swift_tag }}
llvm_project_revision=refs/tags/${{ inputs.swift_tag }}
mimalloc_revision=refs/tags/v2.1.7
sourcekit_lsp_revision=refs/tags/${{ inputs.swift_tag }}
swift_revision=refs/tags/${{ inputs.swift_tag }}
swift_argument_parser_revision=refs/tags/1.4.0
Expand Down Expand Up @@ -480,6 +482,7 @@ jobs:
libxml2_revision: ${{ needs.context.outputs.libxml2_revision }}
libxml2_version: ${{ needs.context.outputs.libxml2_version }}
llvm_project_revision: ${{ needs.context.outputs.llvm_project_revision }}
mimalloc_revision: ${{ needs.context.outputs.mimalloc_revision }}
sourcekit_lsp_revision: ${{ needs.context.outputs.sourcekit_lsp_revision }}
swift_argument_parser_revision: ${{ needs.context.outputs.swift_argument_parser_revision }}
swift_asn1_revision: ${{ needs.context.outputs.swift_asn1_revision }}
Expand Down Expand Up @@ -552,6 +555,7 @@ jobs:
libxml2_revision: ${{ needs.context.outputs.libxml2_revision }}
libxml2_version: ${{ needs.context.outputs.libxml2_version }}
llvm_project_revision: ${{ needs.context.outputs.llvm_project_revision }}
mimalloc_revision: ${{ needs.context.outputs.mimalloc_revision }}
sourcekit_lsp_revision: ${{ needs.context.outputs.sourcekit_lsp_revision }}
swift_argument_parser_revision: ${{ needs.context.outputs.swift_argument_parser_revision }}
swift_asn1_revision: ${{ needs.context.outputs.swift_asn1_revision }}
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/swift-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ on:
required: true
type: string

mimalloc_revision:
required: true
type: string

sourcekit_lsp_revision:
required: true
type: string
Expand Down Expand Up @@ -3193,6 +3197,41 @@ jobs:
Install-Package -Name WixToolset.Sdk -RequiredVersion 4.0.1 -Force
}
- uses: actions/checkout@v4
if: matrix.arch == 'amd64'
with:
repository: microsoft/mimalloc
ref: ${{ inputs.mimalloc_revision }}
path: ${{ github.workspace }}/SourceCache/mimalloc

- name: Build and apply mimalloc
if: matrix.arch == 'amd64'
run: |
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
msbuild ${{ github.workspace }}\SourceCache\mimalloc\ide\vs2022\mimalloc.sln -p:Configuration=Release
$ToolchainBin = "${{ github.workspace }}\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-override.dll" `
-Destination "$ToolchainBin"
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-redirect.dll" `
-Destination "$ToolchainBin"
$MimallocExecutables = @("swift.exe",
"swiftc.exe",
"swift-driver.exe",
"swift-frontend.exe",
"clang.exe",
"clang++.exe",
"clang-cl.exe",
"lld.exe",
"lld-link.exe",
"ld.lld.exe",
"ld64.lld.exe")
foreach ($Exe in $MimallocExecutables) {
# Binary-patch in place
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -f -i -v "$ToolchainBin\$Exe"
# Log the import table
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -l "$ToolchainBin\$Exe"
}
- name: Package Build Tools
run: |
msbuild -nologo -restore -maxCpuCount `
Expand All @@ -3203,6 +3242,7 @@ jobs:
-p:PASSPHRASE=${{ secrets.PASSPHRASE }} `
-p:DEVTOOLS_ROOT=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain `
-p:TOOLCHAIN_ROOT=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain `
-p:ENABLE_MIMALLOC=true `
-p:ProductArchitecture=${{ matrix.arch }} `
-p:ProductVersion=${{ inputs.swift_version }} `
${{ github.workspace }}/SourceCache/swift-installer-scripts/platforms/Windows/bld/bld.wixproj
Expand Down
2 changes: 2 additions & 0 deletions default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@

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

<project remote="github" name="microsoft/mimalloc" path="mimalloc" revision="refs/tags/v2.1.7" />

<project remote="github" name="ninja-build/ninja" path="ninja" groups="notdefault,dependencies" revision="master" />
</manifest>

0 comments on commit c89442d

Please sign in to comment.