Skip to content

GHA/windows: improve build perf with cmake unity batches - #16272

Closed
vszakats wants to merge 8 commits into
curl:masterfrom
vszakats:gha-perf-2
Closed

vszakats wants to merge 8 commits into
curl:masterfrom
vszakats:gha-perf-2

Conversation

@vszakats

@vszakats vszakats commented Feb 8, 2025 •

Copy link
Copy Markdown
Member

Default curl unity builds make a single unit for each target. It means
all target sources are batched together and built in a single compiler
invocation. With multi-core CPUs this doesn't always result in the best
possible performance. This patch enables smaller batches for jobs where
this resulted in shorter build times. These jobs are Cygwin, MSYS2,
MinGW, running on the Windows runners.

Use batch of 30 (meaning 30 sources batched into units), and 32 for
Cygwin/MSYS2 to avoid a unity fallout that's subject to a different PR.

(CMake allows to set the number of sources per unit, not the number
of units, though the latter may be more practical to max out CPU cores.)

Also override to not batch the curlu target because batching lost
a little bit of time there, due to the already existing parallelism when
building the testdeps targets.

For jobs on the macOS and Linux runners jobs were already mostly single
digit or below teen seconds, and batching didn't improve on them
noticeably. On VM jobs, the virtual CPUs are limited, so I didn't
make a try. In AppVeyor and GHA vcpkg jobs (using msbuild), batching
didn't result in conclusive or any gains.

Build times in seconds (curl + testdeps):

Job Before After w curlu=0 Gain
cygwin, CM 19 + 32 = 51 12 + 32 = 44 7
msys2, CM 7 + 15 = 22 5 + 14 = 19 3
mingw gcc U, CM 19 + 30 = 49 13 + 32 = 45 4
mingw ucrt, CM 32 + 42 = 74 15 + 43 = 58 16
mingw clang, CM 15 + 21 = 36 8 + 21 = 29 7
mingw uwp, CM 30 + 40 = 70 14 + 40 = 54 16
mingw gcc, CM 20 + 31 = 51 12 + 31 = 43 8
mingw x86, CM 35 + 40 = 75 15 + 38 = 53 22
dl-mingw, CM 9.5.0 88 + 99 = 187 42 + 101 = 143 44
dl-mingw, CM 7.3.0 U 24 + 32 = 56 17 + 35 = 52 4
Total 131

Total gain per GHA/windows workflow runs: 2m11s

Runs:
Before: https://github.com/curl/curl/actions/runs/13220256084/job/36904342259
After: https://github.com/curl/curl/actions/runs/13220383702/job/36904602981
https://github.com/curl/curl/actions/runs/13220613141/job/36905170104
https://github.com/curl/curl/actions/runs/13222019443/job/36908358550
With curlu tweak: https://github.com/curl/curl/actions/runs/13222239255/job/36908782462

Ref: 116950a #16265


Full table with 'after' results without the curlu tweak for comparison:

Job Before After After w curlu=0 Gain
cygwin, CM 19 + 32 = 51 11 + 34 = 45 12 + 32 = 44 7
msys2, CM 7 + 15 = 22 5 + 16 = 21 5 + 14 = 19 3
mingw gcc U, CM 19 + 30 = 49 13 + 34 = 47 13 + 32 = 45 4
mingw ucrt, CM 32 + 42 = 74 15 + 45 = 60 15 + 43 = 58 16
mingw clang, CM 15 + 21 = 36 8 + 18 = 26 8 + 21 = 29 7
mingw uwp, CM 30 + 40 = 70 14 + 44 = 58 14 + 40 = 54 16
mingw gcc, CM 20 + 31 = 51 13 + 34 = 47 12 + 31 = 43 8
mingw x86, CM 35 + 40 = 75 15 + 39 = 54 15 + 38 = 53 22
dl-mingw, CM 9.5.0 88 + 99 = 187 41 + 108 = 149 42 + 101 = 143 44
dl-mingw, CM 7.3.0 U 24 + 32 = 56 16 + 33 = 49 17 + 35 = 52 4
Total 671 556 540 131

@vszakats vszakats added performance CI Continuous Integration labels Feb 8, 2025
@vszakats
vszakats force-pushed the gha-perf-2 branch 3 times, most recently from fa43080 to ce784b6 Compare February 9, 2025 02:37
@github-actions github-actions Bot added the Windows Windows-specific label Feb 9, 2025
@vszakats vszakats changed the title [WIP] CI: perf tweaks GHA/windows: improve performance by using unity batches Feb 9, 2025
@vszakats vszakats changed the title GHA/windows: improve performance by using unity batches GHA/windows: improve performance with unity batches Feb 9, 2025
@vszakats vszakats changed the title GHA/windows: improve performance with unity batches GHA/windows: improve build perf with cmake unity batches Feb 9, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Feb 9, 2025
Before this patch curl code was redefining `getaddrinfo` and
`freeaddrinfo` system symbols to plug in its debug wrappers. This was
causing pains to avoid applying the redefinitions to system headers
defining these functions, and to the local debug wrappers. Especially
in unity builds. It also required workarounds for systems where these
symbols are already macros.

Introduce curl-namespaced macros for these functions and use them.
This allows to drop all workarounds and makes it work in all envs,
local targets and unity/bundle combinations.

Ref: curl#16272
Ref: 71cf0d1 curl#14772
Ref: 3efba94 curl#14765
Ref: f7d5f47 curl#14399

Closes curl#16274
vszakats added a commit to vszakats/curl that referenced this pull request Feb 9, 2025
Before this patch curl code was redefining `getaddrinfo` and
`freeaddrinfo` system symbols to plug in its debug wrappers. This was
causing pains to avoid applying the redefinitions to system headers
defining these functions, and to the local debug wrappers. Especially
in unity builds. It also required workarounds for systems where these
symbols are already macros.

Introduce curl-namespaced macros for these functions and use them.
This allows to drop all workarounds and makes it work in all envs,
local targets and unity/bundle combinations.

Ref: curl#16272
Ref: 71cf0d1 curl#14772
Ref: 3efba94 curl#14765
Ref: f7d5f47 curl#14399

Closes curl#16274
local repro:

cmake -B bld -G Ninja \
  -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30 -DENABLE_DEBUG=ON \
  -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)"
@vszakats vszakats closed this in 29e4eda Feb 10, 2025
@vszakats
vszakats deleted the gha-perf-2 branch February 10, 2025 11:55
vszakats added a commit that referenced this pull request Feb 13, 2025
Before this patch curl code was redefining `getaddrinfo` and
`freeaddrinfo` system symbols to plug in its debug wrappers. This was
causing pains to avoid applying the redefinitions to system headers
defining these functions, and to the local debug wrappers. Especially
in unity builds. It also required workarounds for systems where these
symbols are already macros.

Introduce curl-namespaced macros for these functions and use them.
This allows to drop all workarounds and makes it work in all envs,
local targets and unity/bundle combinations.

Also drop GHA/windows workaround and use the same unity batch across
all jobs. Follow-up to 29e4eda #16272

Ref: #16272
Ref: 71cf0d1 #14772
Ref: 3efba94 #14765
Ref: f7d5f47 #14399

Closes #16274
vszakats added a commit to vszakats/curl that referenced this pull request Mar 17, 2025
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
Default curl unity builds make a single unit for each target. It means
all target sources are batched together and built in a single compiler
invocation. With multi-core CPUs this doesn't always result in the best
possible performance. This patch enables smaller batches for jobs where
this resulted in shorter build times. These jobs are Cygwin, MSYS2,
MinGW, running on the Windows runners.

Use batch of 30 (meaning 30 sources batched into units), and 32 for
Cygwin/MSYS2 to avoid a unity fallout that's subject to a different PR.

(CMake allows to set the number of sources per unit, not the number
of units, though the latter may be more practical to max out CPU cores.)

Also override to not batch the `curlu` target because batching lost
a little bit of time there, due to the already existing parallelism when
building the `testdeps` targets.

For jobs on the macOS and Linux runners jobs were already mostly single
digit or below teen seconds, and batching didn't improve on them
noticeably. On VM jobs, the virtual CPUs are limited, so I didn't
make a try. In AppVeyor and GHA vcpkg jobs (using msbuild), batching
didn't result in conclusive or any gains.

Build times in seconds (curl + testdeps):
Job                  |          Before | After w curlu=0 | Gain
:--------------------| :-------------- | :-------------- | :---
cygwin, CM           |   19 + 32 =  51 |  12 +  32 =  44 |    7
msys2, CM            |    7 + 15 =  22 |   5 +  14 =  19 |    3
mingw gcc U, CM      |   19 + 30 =  49 |  13 +  32 =  45 |    4
mingw ucrt, CM       |   32 + 42 =  74 |  15 +  43 =  58 |   16
mingw clang, CM      |   15 + 21 =  36 |   8 +  21 =  29 |    7
mingw uwp, CM        |   30 + 40 =  70 |  14 +  40 =  54 |   16
mingw gcc, CM        |   20 + 31 =  51 |  12 +  31 =  43 |    8
mingw x86, CM        |   35 + 40 =  75 |  15 +  38 =  53 |   22
dl-mingw, CM 9.5.0   |   88 + 99 = 187 |  42 + 101 = 143 |   44
dl-mingw, CM 7.3.0 U |   24 + 32 =  56 |  17 +  35 =  52 |    4
Total                |                 |                 |  131

Total gain per GHA/windows workflow runs: 2m11s

Runs:
Before: https://github.com/curl/curl/actions/runs/13220256084/job/36904342259
After: https://github.com/curl/curl/actions/runs/13220383702/job/36904602981
       https://github.com/curl/curl/actions/runs/13220613141/job/36905170104
       https://github.com/curl/curl/actions/runs/13222019443/job/36908358550
With curlu tweak: https://github.com/curl/curl/actions/runs/13222239255/job/36908782462

Ref: 116950a curl#16265

Closes curl#16272
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
Before this patch curl code was redefining `getaddrinfo` and
`freeaddrinfo` system symbols to plug in its debug wrappers. This was
causing pains to avoid applying the redefinitions to system headers
defining these functions, and to the local debug wrappers. Especially
in unity builds. It also required workarounds for systems where these
symbols are already macros.

Introduce curl-namespaced macros for these functions and use them.
This allows to drop all workarounds and makes it work in all envs,
local targets and unity/bundle combinations.

Also drop GHA/windows workaround and use the same unity batch across
all jobs. Follow-up to 29e4eda curl#16272

Ref: curl#16272
Ref: 71cf0d1 curl#14772
Ref: 3efba94 curl#14765
Ref: f7d5f47 curl#14399

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

Labels

CI Continuous Integration cmdline tool performance tests Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant