Commit 0cfeb00
fix: Optionally exclude directories from list_files_under for performance (#1488)
This PR adds an `exclude_directories` argument to
`repository_files.list_files_under` which resulted in a massive
performance improvement for packages with lots of resources.
I noticed that it was taking a really long time to "fetch" a package
that was local to my machine, so there was no actual network operations
required.
I dug into the issue and it's actually from a change I added in [this
PR](#1039)
to expand certain types of resources into a list of their assets. The
overwhelming majority of the time was being spent on the `if not
repository_files.is_directory(repository_ctx, p)` check inside of the
loop. By omitting directories from the result of `list_files_under` we
can skip all of that work.
### Before - 225s
<img width="1543" alt="image"
src="https://github.com/user-attachments/assets/67f6f5e2-66b7-4143-95fd-8401ea6c8347"
/>
### After - 2s
<img width="1300" alt="image"
src="https://github.com/user-attachments/assets/396c6eb2-4b59-41ab-811d-3e10bacba243"
/>
I didn't see any uses of `list_files_under` that were relying on it to
contain directories. Should we change the behavior to never include
directories?
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>1 parent 881ec3f commit 0cfeb00
2 files changed
+12
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
321 | 318 | | |
322 | 319 | | |
323 | 320 | | |
| |||
1023 | 1020 | | |
1024 | 1021 | | |
1025 | 1022 | | |
| 1023 | + | |
1026 | 1024 | | |
1027 | 1025 | | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | 1026 | | |
1037 | | - | |
1038 | 1027 | | |
1039 | 1028 | | |
1040 | 1029 | | |
1041 | | - | |
1042 | | - | |
| 1030 | + | |
1043 | 1031 | | |
1044 | 1032 | | |
1045 | 1033 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| 100 | + | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
0 commit comments