Skip to content

Skip redundant find_package(Python3) in generator extensions - #266

Open
mjcarroll wants to merge 1 commit into
rollingfrom
guard-redundant-find-package-python3
Open

Skip redundant find_package(Python3) in generator extensions#266
mjcarroll wants to merge 1 commit into
rollingfrom
guard-redundant-find-package-python3

Conversation

@mjcarroll

@mjcarroll mjcarroll commented Aug 22, 2026

Copy link
Copy Markdown
Member

Companion to ros2/rosidl#984.

Every rosidl generator extension calls find_package(Python3 REQUIRED
COMPONENTS ...) unconditionally.  Because ament_execute_extensions includes
each extension into the same scope, a single interface package runs that
search once per registered generator -- 13 times for a default rolling
workspace.

CMake does not memoize this.  Each repeat re-enters FindPython/Support.cmake
and re-interrogates the interpreter with roughly seven subprocesses.  On
Windows, where CreateProcess for python.exe costs ~60ms locally and far more
on a CI runner, the repeats dominate configure time.

Guard each call on the imported target, exactly as ament_cmake_core's
python.cmake already does.  Imported targets are directory scoped, so the
target created by the first search is visible to every later extension.

Companion to ros2/rosidl.  With all four repos patched, configure of
builtin_interfaces drops from 17.6s to 13.1s on Windows (median of 5),
python.exe spawns from 92 to 22, and the generated build.ninja is
byte identical.

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
@mjcarroll
mjcarroll force-pushed the guard-redundant-find-package-python3 branch from ed8b420 to b4a110f Compare August 23, 2026 01:55
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.

1 participant