8000 COMP: speed up Linux compilation by using precompiled headers by achataigner · Pull Request #7908 · Slicer/Slicer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

COMP: speed up Linux compilation by using precompiled headers #7908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

achataigner
Copy link
Contributor
@achataigner achataigner commented Aug 28, 2024

COMP: Speed up Linux compilation by using precompiled headers

This branch was only tested on Linux Ubuntu 22.04 LTS.

It is quite easy to speed up compilation in Libs and Base thanks to
vtk, itk and qt precompiled headers.

Build test done:

  • DBUILD_TESTING=OFF cmake option
  • with 12 jobs for the 12 cores of my intel i7 CPU
  • commands:
    cd build-dir/Slicer-Build/Libs && make clean && make -j12
    cd build-dir/Slicer-Build/Base && make clean && make -j12

Build times:
Libs:
without precompiled headers: 44m 28s
with precompiled headers: 18m9s

Base :
without precompiled headers: 10m 35s
with precompiled headers: 2m 54s

This branch is simply a proposal to show the benefits of precompiled headers,
do not hesitate to ask questions and propose better code.

Precompiled headers are harder to use in Modules because the target library
and the source binary must use the same compilation flags (for instance *_EXPORTS flag must be the same)

@achataigner achataigner force-pushed the aymeric/use-qt-and-vtk-precompiled-headers-to-speed-up-build-in-libs-and-base branch 3 times, most recently from 321bcea to 6ce6b1d Compare August 28, 2024 12:45
This branch was only tested on Linux Ubuntu 22.04 LTS.

It is quite easy to speed up compilation in Libs and Base thanks to
vtk, itk and qt precompiled headers.

Build test done:
- DBUILD_TESTING=OFF cmake option
- with 12 jobs for the 12 cores of my intel i7 CPU
- commands:
  cd build-dir/Slicer-Build/Libs && make clean && make -j12
  cd build-dir/Slicer-Build/Base && make clean && make -j12

Build times:
  Libs:
    without precompiled headers: 44m 28s
    with precompiled headers: 18m9s

  Base :
    without precompiled headers: 10m 35s
    with precompiled headers: 2m 54s

This branch is simply a proposal to show the benefits of precompiled headers,
do not hesitate to ask questions and propose better code.

Precompiled headers are harder to use in Modules because the target library
 and the source binary must use the same compilation flags (for instance *_EXPORTS flag must be the same)
@achataigner achataigner force-pushed the aymeric/use-qt-and-vtk-precompiled-headers-to-speed-up-build-in-libs-and-base branch from 6ce6b1d to 8f6b1dd Compare August 28, 2024 12:59
@achataigner
Copy link
Contributor Author
achataigner commented Aug 30, 2024

@lassoan @jcfr @RafaelPalomar What do you think about this pull request ?

@lassoan
Copy link
Contributor
lassoan commented Aug 30, 2024

Thank you @achataigner, this looks like a potentially significant speedup!

My computer builds Slicer from scratch (including all dependencies) in about 30 minutes with gcc on Linux, but MSVC on Windows takes hours. So, I'm curious to see how much improvement can be achieved on Windows. I've started a build. I'll let you know when it is done.

@lassoan
Copy link
Contributor
lassoan commented Sep 1, 2024

I've built Slicer from scratch on Windows in release mode and got the following results:

Slicer main:

  • build time: 5 hours 50 minutes
  • build tree size: 13.9GB

With precompiled headers in this pull request:

  • build time: 5 hours 36 minutes (4% faster)
  • build tree size: 14.4GB (3.6% larger)

(I've also tried to speed up the build process on Windows by doing parallel build: %CMAKE_EXE% --build . --config Release --parallel 16 -- /p:CL_MPcount=16 - with this the build time was 1 hour 47 minutes.)

Based on these results, I'm not sure if this is worth the trouble. But maybe just the proposed changes are ineffective on Windows.

@achataigner
Copy link
Contributor Author

This branch only speeds up Libs and Base build so I am not surprised by your results.
It would be interesting to measure a rebuild of Libs and a rebuild of Base to compare Windows and Linux results.
Naturally I am also curious about MacOS.

Again, this branch is a draft, we could use precompiled header in other libs than Libs and Base and get real improvements on the whole build. Moreover precompiled header is quite easy to use in CMakeLists.txt, it does not really complexify current CMake code.

@jcfr @RafaelPalomar @pieper What are your opinions ?

@pieper
Copy link
Member
pieper commented Sep 2, 2024

Has anyone tried profiling the build, something like this suggestion? Personally I find SimpleITK, Testing, and CLIs to be the slowest parts of the build, but I never find it enough of a bottleneck to invest time in addressing.

@achataigner
Copy link
Contributor Author

I just started a Ninja build.
I've never used this build system before and it sounds promising, do you have any experience with it to build slicer ?

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

Successfully merging this pull request may close these issues.

4 participants
0