Skip to content

Build native extensions in parallel (multi-core) - #100

Open
JustinMDotNet wants to merge 2 commits into
microsoft:mainfrom
JustinMDotNet:dev/jumoran/pr-build-parallel-flags
Open

Build native extensions in parallel (multi-core)#100
JustinMDotNet wants to merge 2 commits into
microsoft:mainfrom
JustinMDotNet:dev/jumoran/pr-build-parallel-flags

Conversation

@JustinMDotNet

@JustinMDotNet JustinMDotNet commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Speed up native extension builds by compiling with all available CPU cores instead of single-threaded.

What

Add a parallel-build flag to every native CMake/make invocation that was building single-threaded:

Main extension builds

  • Java / Python (Windows .cmd, Linux .sh): cmake --build ... --target install --parallel
  • GoogleTest (Windows): mingw32-make all -> mingw32-make -j all
  • GoogleTest (Linux): cmake --build ... --target install --parallel

Test / R builds (so the test builds match their main-extension counterparts)

  • Python extension test (Windows .cmd, Linux .sh): add --parallel
  • R extension + R extension test (Linux .sh): add --parallel
  • dotnet-core-CSharp extension test native cmake step (Windows .cmd): add --parallel

The Windows R / GoogleTest builds use mingw32-make -j all; the managed dotnet build steps already compile multi-core via /m.

Why

These were the native builds still compiling on a single core. --parallel defaults to the available core count; there is no change to build outputs or targets. After this change no cmake --build ... --target install invocation is left single-threaded.

Performance

The flag parallelizes the C++ compile phase, which scales with cores up to the number of translation units per extension (Java 16, R 16, Python 13, CSharp native shim 3). The gain is Amdahl-bounded: the serial cmake configure and shared-lib link within each step, and the separate package-restore step, do not parallelize. Realistic expectation is roughly a 2-4x reduction in each native compile step on a typical 4-8 core machine (the 3-TU CSharp shim benefits least; Java/R/Python most) rather than a whole-build speedup.

No hard before/after numbers are included: this repo has no committed CI that builds these scripts (the only PR checks are GitHub-managed CodeQL default setup and license/cla, and CodeQL's c-cpp analysis uses its own autobuild, not these scripts). Timings should be captured from whatever process runs these scripts (release/official builds and local developer builds) by comparing per-step wall-clock before vs. after.

Risk

Low. Eleven one-line changes; error handling untouched.

JustinMDotNet and others added 2 commits July 24, 2026 13:34
Add parallel-build flags to the native CMake/make invocations that were
building single-threaded, matching the pattern already used by the R,
ONNX and EKM extensions:
- Java/Python (windows .cmd, linux .sh): cmake --build ... --parallel
- GoogleTest windows: mingw32-make -j all
- GoogleTest linux: cmake --build ... --parallel

--parallel defaults to the available core count; no behavioral change to
outputs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: acb7e6f8-cf0c-4635-92e7-df8559d2d677
Extend the --parallel build flag to the sibling native CMake builds that
were still compiling single-threaded:
- Python extension test (windows .cmd, linux .sh)
- R extension + R extension test (linux .sh)
- dotnet-core-CSharp extension test native cmake step (windows .cmd)

Completes the parallelization so the extension test builds match their
main-extension counterparts. No behavioral change to outputs or targets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JustinMDotNet
JustinMDotNet marked this pull request as ready for review July 27, 2026 18:44
Copilot AI review requested due to automatic review settings July 27, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR speeds up CI by enabling parallel compilation for native extension builds (CMake builds and MinGW make) so native code uses available CPU cores instead of building single-threaded.

Changes:

  • Add --parallel to all cmake --build ... --target install/INSTALL invocations across Java, Python, R, GoogleTest, and dotnet-core-CSharp test builds.
  • Enable parallel MinGW builds for Windows GoogleTest via mingw32-make -j all.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/googletest/build/windows/build-googletest.cmd Build GoogleTest with parallel MinGW make (-j).
test/googletest/build/linux/build-googletest.sh Build/install GoogleTest with cmake --build --parallel.
language-extensions/R/test/build/linux/build-RExtension-test.sh Build/install R extension tests with cmake --build --parallel.
language-extensions/R/build/linux/build-RExtension.sh Build/install R extension with cmake --build --parallel.
language-extensions/python/test/build/windows/build-pythonextension-test.cmd Build/install Python extension tests with cmake --build --parallel.
language-extensions/python/test/build/linux/build-pythonextension-test.sh Build/install Python extension tests with cmake --build --parallel.
language-extensions/python/build/windows/build-python-extension.cmd Build/install Python extension with cmake --build --parallel.
language-extensions/python/build/linux/build-python-extension.sh Build/install Python extension with cmake --build --parallel.
language-extensions/java/build/windows/build-java-extension.cmd Build/install Java extension with cmake --build --parallel.
language-extensions/java/build/linux/build-java-extension.sh Build/install Java extension with cmake --build --parallel.
language-extensions/dotnet-core-CSharp/test/build/windows/build-dotnet-core-CSharp-extension-test.cmd Build/install native dotnet-core-CSharp test components with cmake --build --parallel.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants