Speed-up CMake builds by allowing a persistent Cmake build dir #788
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.
When we build with
pip install -e . --no-build-isolation
,cmake
currently always relies onself.build_temp
:https://github.com/pytorch/torchcodec/blob/de517c51f10f39d7d5e9a34714ecd00fece7ad36/setup.py#L129-L135
self.build_temp
is automatically created at some point - not sure by what, whether it'spip
orsetuptools
or something else. It doesn't matter. What matters is that it's a temporary directory that changes for each invocation ofpip install -e . --no-build-isolation
. And because it changes each time, it means the cmake configuration step is re-done each time as well. And that takes time.This PR adds a
TORCHCODEC_CMAKE_BUILD_DIR
that can be optionally specified to indicate a persistent build dir for cmake. This should greatly speed-up subsequent builds by avoiding the config step, and by avoiding re-compiling most files (but you should be using ccache anyway!!)I recommend doing something like
conda env config vars set TORCHCODEC_CMAKE_BUILD_DIR=${PWD}/build
where PWD is the torchcodec dir, so that this variable is set automatically when you activate your conda env.Here's a diff of the first and second
TORCHCODEC_CMAKE_BUILD_DIR=./build pip install -e . --no-build-isolation
invocations. Note the configuration step, and the lack of recompilation.