Skip to content
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

[CMake] Speed up copying of headers and tutorials #17607

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hageboeck
Copy link
Member

@hageboeck hageboeck commented Feb 4, 2025

  • Move the copy of artifacts (e.g. tutorials) from build time to configure time, and use a faster copy function.
  • At build time, replace the one-by-one copy of headers by copy in batches.

Here are some results:

make -j6 move_headers New Old
1st invocation 10.7 s 34.5 s
2nd invocation 2.7 s 3.8 s
Invocation after touching a header in core/ 3.1 s 4.2 s
Invocation after touching a header in RooFit/hs3 2.9 s 3.9 s
make -j6 move_artifacts New Old
1st invocation 2.2 s 18 s
2nd invocation 2.2 s 2.4 s

Although there is one situation where the new approach takes longer (headers that end up in <buildDir>/include were touched), the benefits especially on first build or when no header was touched seem to outweigh the disadvantages.

Fix #14953

Move the copy of artifacts from build time to configure time,
and use a faster copy function.

Fix root-project#14953.
@hageboeck hageboeck self-assigned this Feb 4, 2025
@hageboeck hageboeck requested a review from bellenot as a code owner February 4, 2025 11:00
@hageboeck hageboeck requested a review from dpiparo February 4, 2025 11:02
@bellenot
Copy link
Member

bellenot commented Feb 4, 2025

The error on Windows is related to this PR:

error MSB8066: Custom build for 'C:\ROOT-CI\build\CMakeFiles\b4bf4ec5a2a2748fa3fe14aac0b491c8\Bswapcpy.h.rule;C:\ROOT-CI\build\CMakeFiles\d52c4a97b544285cfdcb9662e36a1605\BasicFCN.h.rule;C:\ROOT-CI\build\CMakeFiles\5cbe746a32c517ce8263460eaed96b46\eglew.h.rule;C:\ROOT-CI\build\CMakeFiles\6f62a2407de5b487a7d37393f911fe87\AdaptiveIntegratorMultiDim.h.rule;C:\ROOT-CI\build\CMakeFiles\f946b1f1f35c1bd8f320cb3e49e00bca\3DConversions.h.rule;C:\ROOT-CI\build\CMakeFiles\d4bf7379258006facfcfa53f75f5956b\ABObj.h.rule;C:\ROOT-CI\build\CMakeFiles\a35c8b97151be13ed3d204ad6ed80264\RAnyObjectHolder.hxx.rule;C:\ROOT-CI\build\CMakeFiles\456e85c62d06e0cd87d98ee60dcc2e4f\EExecutionPolicy.hxx.rule;C:\ROOT-CI\build\CMakeFiles\c353aed7a3bd6dbf0923bb9dc4fba686\ActionHelpers.hxx.rule;C:\ROOT-CI\build\CMakeFiles\9bbd6f9b9a1ccee3bcd008c06562308d\RFieldFundamental.hxx.rule;C:\ROOT-CI\build\CMakeFiles\3fbab4c4bb0860c35dbc49b686024422\daos.h.rule;C:\ROOT-CI\build\CMakeFiles\06709d940c4eaf4b90467c901d21fad5\CodegenImpl.h.rule;C:\ROOT-CI\build\CMakeFiles\2600cfd80747fb5960de4549ed2956e4\MathFuncs.h.rule;C:\ROOT-CI\build\CMakeFiles\193c5d220ee00c87398efe41e5bca113\LikelihoodGradientWrapper.h.rule;C:\ROOT-CI\build\CMakeFiles\7e106373c3f52de7795b17f694a854fe\JSONIO.h.rule;C:\ROOT-CI\build\CMakeFiles\c562cae4eae5394921ddc3d0cafa5f56\RooCatTypeLegacy.h.rule;C:\ROOT-CI\build\CMakeFiles\ebec96819e385d9ea45a1b2d103e31b8\AsymptoticCalculator.h.rule;C:\ROOT-CI\build\CMakeFiles\cd2d88b30ee96ff2fdca17cad3e08856\Asimov.h.rule;C:\ROOT-CI\build\CMakeFiles\0bd4f58f57ed53aeade166f8902ab30f\HistFactoryImpl.h.rule;C:\ROOT-CI\build\CMakeFiles\4ff935d273915365070a61ee0cd1b02c\BDTEventWrapper.h.rule;C:\ROOT-CI\build\CMakeFiles\db29aecca489daaa0f06f6367b1d3b81\RBatchGenerator.hxx.rule;C:\ROOT-CI\build\CMakeFiles\ec821efde375e08e4c351de8c63c89b6\Adadelta.h.rule;C:\ROOT-CI\build\CMakeFiles\addb20638c349f1661791f2822729cf7\Cpu.h.rule;C:\ROOT-CI\build\CMakeFiles\1690471466c052fbb378442159d120a1\CpuBuffer.h.rule;C:\ROOT-CI\build\CMakeFiles\c9afbfdea5ae89c0c83ece15ff85d3eb\DataLoader.h.rule;C:\ROOT-CI\build\CMakeFiles\c0ea46944f6274260ea7991effa94d3e\ContextHandles.h.rule;C:\ROOT-CI\build\CMakeFiles\36bb35dee450defb44862eb7f6abee62\GRULayer.h.rule;C:\ROOT-CI\build\CMakeFiles\d580fcda3530414ad56cc58ed53c3de0\bbox.h.rule;C:\ROOT-CI\build\CMakeFiles\c9dbea440c663f8cf1755fecccca54fd\TF1Data.h.rule;C:\ROOT-CI\build\CMakeFiles\837d695c63a67b677c4a78432d56e457\move_headers.rule;C:\ROOT-CI\src\CMakeLists.txt' exited with code 9020. [C:\ROOT-CI\build\move_headers.vcxproj]

Copy link

github-actions bot commented Feb 4, 2025

Test Results

    18 files      18 suites   4d 1h 53m 53s ⏱️
 2 690 tests  2 690 ✅ 0 💤 0 ❌
46 724 runs  46 724 ✅ 0 💤 0 ❌

Results for commit 594345f.

♻️ This comment has been updated with latest results.

To copy headers to the build tree, ROOT was creating one target per header.
Headers are copied in packs of 100 (Windows doesn't support very long command lines).
This significantly reduces the number of CMake targets and speeds up the build.

A simple test that only moves headers:
make -j6 move_headers   New     Old
1st invocation          10.7 s  34.5 s
2nd invocation           2.7 s   3.8 s

Fix root-project#14953.
@hageboeck
Copy link
Member Author

hageboeck commented Feb 5, 2025

The error on Windows is related to this PR:

error MSB8066: Custom build for 'C:\ROOT-CI\build\CMakeFiles\b4bf4ec5a2a2748fa3fe14aac0b491c8\Bswapcpy.h.rule;C:\ROOT-CI\build\CMakeFiles\d52c4a97b544285cfdcb9662e36a1605\BasicFCN.h.rule;C:\ROOT-CI\build\CMakeFiles\5cbe746a32c517ce8263460eaed96b46\eglew.h.rule;C:\ROOT-CI\build\CMakeFiles\6f62a2407de5b487a7d37393f911fe87\AdaptiveIntegratorMultiDim.h.rule;C:\ROOT-CI\build\CMakeFiles\f946b1f1f35c1bd8f320cb3e49e00bca\3DConversions.h.rule;C:\ROOT-CI\build\CMakeFiles\d4bf7379258006facfcfa53f75f5956b\ABObj.h.rule;C:\ROOT-CI\build\CMakeFiles\a35c8b97151be13ed3d204ad6ed80264\RAnyObjectHolder.hxx.rule;C:\ROOT-CI\build\CMakeFiles\456e85c62d06e0cd87d98ee60dcc2e4f\EExecutionPolicy.hxx.rule;C:\ROOT-CI\build\CMakeFiles\c353aed7a3bd6dbf0923bb9dc4fba686\ActionHelpers.hxx.rule;C:\ROOT-CI\build\CMakeFiles\9bbd6f9b9a1ccee3bcd008c06562308d\RFieldFundamental.hxx.rule;C:\ROOT-CI\build\CMakeFiles\3fbab4c4bb0860c35dbc49b686024422\daos.h.rule;C:\ROOT-CI\build\CMakeFiles\06709d940c4eaf4b90467c901d21fad5\CodegenImpl.h.rule;C:\ROOT-CI\build\CMakeFiles\2600cfd80747fb5960de4549ed2956e4\MathFuncs.h.rule;C:\ROOT-CI\build\CMakeFiles\193c5d220ee00c87398efe41e5bca113\LikelihoodGradientWrapper.h.rule;C:\ROOT-CI\build\CMakeFiles\7e106373c3f52de7795b17f694a854fe\JSONIO.h.rule;C:\ROOT-CI\build\CMakeFiles\c562cae4eae5394921ddc3d0cafa5f56\RooCatTypeLegacy.h.rule;C:\ROOT-CI\build\CMakeFiles\ebec96819e385d9ea45a1b2d103e31b8\AsymptoticCalculator.h.rule;C:\ROOT-CI\build\CMakeFiles\cd2d88b30ee96ff2fdca17cad3e08856\Asimov.h.rule;C:\ROOT-CI\build\CMakeFiles\0bd4f58f57ed53aeade166f8902ab30f\HistFactoryImpl.h.rule;C:\ROOT-CI\build\CMakeFiles\4ff935d273915365070a61ee0cd1b02c\BDTEventWrapper.h.rule;C:\ROOT-CI\build\CMakeFiles\db29aecca489daaa0f06f6367b1d3b81\RBatchGenerator.hxx.rule;C:\ROOT-CI\build\CMakeFiles\ec821efde375e08e4c351de8c63c89b6\Adadelta.h.rule;C:\ROOT-CI\build\CMakeFiles\addb20638c349f1661791f2822729cf7\Cpu.h.rule;C:\ROOT-CI\build\CMakeFiles\1690471466c052fbb378442159d120a1\CpuBuffer.h.rule;C:\ROOT-CI\build\CMakeFiles\c9afbfdea5ae89c0c83ece15ff85d3eb\DataLoader.h.rule;C:\ROOT-CI\build\CMakeFiles\c0ea46944f6274260ea7991effa94d3e\ContextHandles.h.rule;C:\ROOT-CI\build\CMakeFiles\36bb35dee450defb44862eb7f6abee62\GRULayer.h.rule;C:\ROOT-CI\build\CMakeFiles\d580fcda3530414ad56cc58ed53c3de0\bbox.h.rule;C:\ROOT-CI\build\CMakeFiles\c9dbea440c663f8cf1755fecccca54fd\TF1Data.h.rule;C:\ROOT-CI\build\CMakeFiles\837d695c63a67b677c4a78432d56e457\move_headers.rule;C:\ROOT-CI\src\CMakeLists.txt' exited with code 9020. [C:\ROOT-CI\build\move_headers.vcxproj]

@bellenot I might have found the problem: The command line seems to be too long. After splitting the copy command in packs of 100 (there is more than 1000 headers otherwise), the build seemed to succeed. Let's wait for the latest run.

DEPENDS ${CMAKE_SOURCE_DIR}/${artifact_file})
list(APPEND artifact_files_builddir ${CMAKE_BINARY_DIR}/${artifact_file})
endif()
file(COPY ${DIR_TO_COPY} DESTINATION ${CMAKE_BINARY_DIR}
Copy link
Member

Choose a reason for hiding this comment

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

The file(COPY_FILE command as a ONLY_IF_DIFFERENT options, does this syntax means that the file are copied at reconfigure time?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess the question is whether they should be recopied every time. Currently that's the case, so one could move to COPY_FILE ... ONLY_IF_DIFFERENT.
However, this is not supported in CMake 3.20, which is our minimum CMake version.

macro(ROOT_CREATE_HEADER_COPY_TARGETS)
get_property(HEADER_COPY_LISTS GLOBAL PROPERTY ROOT_HEADER_COPY_LISTS)
list(REMOVE_DUPLICATES HEADER_COPY_LISTS)
foreach(COPY_LIST ${HEADER_COPY_LISTS})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
foreach(COPY_LIST ${HEADER_COPY_LISTS})
foreach(copy_list ${HEADER_COPY_LISTS})

We seems to tend to use lower case for variables ...

Copy link
Member Author

Choose a reason for hiding this comment

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

OK ...

Copy link
Member

@pcanal pcanal left a comment

Choose a reason for hiding this comment

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

With the copy of the artefact (seemingly) only at configure time, we have the following 'failures':

$ echo >> src/tutorials/hsimple.C 
$ ls -l src/tutorials/hsimple.C tutorials/hsimple.C 
-rw-r--r--. 1 pcanal us_cms 3572 Feb  5 17:41 src/tutorials/hsimple.C
-rw-r--r--. 1 pcanal us_cms 3571 Feb  5 16:23 tutorials/hsimple.C
$ ninja
[2/2] Updating etc/gitinfo.txt.
-- Found Git: /usr/bin/git (found version "2.43.5") 
$ ls -l src/tutorials/hsimple.C tutorials/hsimple.C 
-rw-r--r--. 1 pcanal us_cms 3572 Feb  5 17:41 src/tutorials/hsimple.C
-rw-r--r--. 1 pcanal us_cms 3571 Feb  5 16:23 tutorials/hsimple.C

I.e. the copied hsimple.C is not updated after a local modification in the source.

@hageboeck
Copy link
Member Author

With the copy of the artefact (seemingly) only at configure time, we have the following 'failures':

$ echo >> src/tutorials/hsimple.C 
$ ls -l src/tutorials/hsimple.C tutorials/hsimple.C 
-rw-r--r--. 1 pcanal us_cms 3572 Feb  5 17:41 src/tutorials/hsimple.C
-rw-r--r--. 1 pcanal us_cms 3571 Feb  5 16:23 tutorials/hsimple.C
$ ninja
[2/2] Updating etc/gitinfo.txt.
-- Found Git: /usr/bin/git (found version "2.43.5") 
$ ls -l src/tutorials/hsimple.C tutorials/hsimple.C 
-rw-r--r--. 1 pcanal us_cms 3572 Feb  5 17:41 src/tutorials/hsimple.C
-rw-r--r--. 1 pcanal us_cms 3571 Feb  5 16:23 tutorials/hsimple.C

I.e. the copied hsimple.C is not updated after a local modification in the source.

That was my intention. I wanted to reduce the number of CMake targets, since I consider the macros and tutorials mostly stable.
I would anyway recommend to root.exe <sourceDir>/<macro> instead of make -jX; root.exe <buildDir>/<macro>

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.

[cmake] Glob when copying headers and tutorials
3 participants