Skip to content

Swap outer and inner loops in write_python_part()#2861

Merged
messense merged 1 commit intoPyO3:mainfrom
e-nomem:swap-loops-python-part
Nov 20, 2025
Merged

Swap outer and inner loops in write_python_part()#2861
messense merged 1 commit intoPyO3:mainfrom
e-nomem:swap-loops-python-part

Conversation

@e-nomem
Copy link
Copy Markdown
Contributor

@e-nomem e-nomem commented Nov 19, 2025

Of the two loops (walking the directory tree and iterating over the python packges), the directory traversal is the more expensive one. It should be the outer loop so we only do it once.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the write_python_part() function by reversing the loop nesting order to perform expensive directory traversal only once instead of once per Python package.

Key Changes:

  • Moved directory tree traversal (WalkBuilder) to the outer loop
  • Changed the package filtering logic from checking a single package to using .any() to check against all packages
  • Reduced the number of directory tree walks from N (number of packages) to 1

@messense messense merged commit f274d9a into PyO3:main Nov 20, 2025
51 checks passed
@e-nomem e-nomem deleted the swap-loops-python-part branch November 20, 2025 06:53
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.

3 participants