Skip to content

Improve .gitignore iteration speed #1103

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

Merged
merged 1 commit into from
Jun 19, 2025

Conversation

silversquirl
Copy link
Contributor

Using os.walk instead of Path().rglob can be 10x faster in deeply nested directory structures. This is a significant saving on certain projects, where just this iteration can take up to 3 or 4 seconds.

An even better approach would be to parse gitignore files lazily, as the directory tree is traversed later in this function. Another optimization would be to prune ignored directories while walking the directory tree, so they aren't even explored.

However, just the single optimization in this PR already reduces the impact of this code significantly, bringing it from almost 3s in my profile to just 0.4s.

@silversquirl silversquirl force-pushed the gitignore-iteration branch from f7b210a to 685ae95 Compare June 18, 2025 14:33
@henryiii
Copy link
Collaborator

henryiii commented Jun 18, 2025

Also see #1048, which will help a lot (it's the second optimization you mentioned), though it's not backward compatible so it's planned for the next version.

I'll fix the failure with 3.13.4 (done in #1104), that version of Python is broken on Windows for building (on all backends).

@silversquirl
Copy link
Contributor Author

silversquirl commented Jun 18, 2025

Can anyone confirm whether these CI failures are spurious? The docs one definitely is, but I'm not sure about the tests

Oops, I can't read apparently! You already mentioned that version is broken on windows :)

@LecrisUT
Copy link
Collaborator

Yes, only the windows failure is actionable. Fedora rawhide is borked until python3.14 packages are being rebuilt

@henryiii henryiii force-pushed the gitignore-iteration branch from 685ae95 to 20caa1f Compare June 18, 2025 19:59
@henryiii
Copy link
Collaborator

Path.walk exists but needs 3.12, sadly. :)

@henryiii henryiii merged commit a7d5bf4 into scikit-build:main Jun 19, 2025
58 checks passed
@henryiii
Copy link
Collaborator

Thanks!

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