Improve incremental build speeds by about 100% #1159
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request speeds up incremental building of an application using the Pico SDK. I think the incremental build time is really important for productivity: you want to make a change to the code and then see the results a few seconds later without getting distracted by other things during long build times.
Status quo
On Windows under MSYS2, using version 1.4.0 of the pico-sdk (2e6142b), when I do an incremental build of the
hello_pio
example in commit a7ad171 of pico-examples, it takes about 5.9 seconds and here is the output:In this 5.9 second build, it looks like nearly 4 seconds are being spent to check if elf2uf2 and pioasm need to be rebuilt.
This is actually the shortest possible build time because I did not change any code. If I modify
pio/hello_pio/hello.c
, the build time goes up to about 7 s. (These build times are not reliable and seem to vary by a second or so if I wait and try them later.)Solution
This pull request removes the lines that say
BUILD_AWAYS 1 # force dependency checking
in the calls toExternalProject_Add
intools/FindPioasm.cmake
andtools/FindELF2UF2.cmake
. With this change, an incremental build ofhello_pio
with no code changes takes 2.7 seconds:If there has been a code change, that time goes up to about 3.6 seconds.
It's not clear exactly why
BUILD_ALWAYS
is set to 1. The comment on that line is brief, and the code has been like that since the initial release of the Pico SDK. Note that with theBUILD_ALWAYS
line removed, pioasm and elf2uf2 will not be automatically recompiled when the source code of those projects changes. To benefit from changes in those projects, users will have to remove theirbuild
directory and start again, or they can just go intobuild/pioasm
orbuild/elf2uf2
and runmake
. I would hope that these utilities are stable enough that this will not cause major problems for most of the users, and the users would appreciate the faster build times. If you ever want to force everyone to rebuild those tools after a particularly important change, I would think you could do something like change the CMake target name (that should force everyone to rebuild those tools once, instead of making them rebuild them every time they compile their code). You could even bake the SDK version number into the CMake target name to make this process automatic (I haven't tried that).Future work
By the way, there are some signs that the code in FindPioasm.cmake and FindELF2UF2.cmake are not really operating the way one would expect. Each file has three different
if
statements to check whether we have found/configured the external utility, and those checks could be reduced to one. (I succeeded in doing that on an unpublished branch.) Also, due to the way CMake variable and target scopes work, I found that the code in those files runs many times in a project like pico-examples that builds multiple RP2040 applications, even though you would think it would just run once. I might make another pull request later to further improve these files. Would there be any interest in allowing the use of externalpioasm
andelf2uf2
utilities found on the PATH, which is probably the best way to speed up incremental build times?