Commit a7d5bf4
authored
fix: improve .gitignore iteration speed (#1103)
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.1 parent faad1bb commit a7d5bf4
1 file changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
0 commit comments