Skip to content

Commit 796466b

Browse files
committed
Optimize path filtering by skipping common massive directories during traversal
1 parent f2c1fa2 commit 796466b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/patterns/path_filter.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,25 @@ impl PathFilter {
189189
let root = root.as_ref();
190190
let mut files = Vec::new();
191191

192-
for entry in WalkDir::new(root).follow_links(false).into_iter().filter_map(|e| e.ok()) {
192+
// OPTIMIZATION: Use filter_entry to skip massive directories BEFORE entering them
193+
let walker = WalkDir::new(root).follow_links(false).into_iter().filter_entry(|e| {
194+
let name = e.file_name().to_string_lossy();
195+
196+
// SKIP common massive directories to prevent IO floods
197+
if name == ".git"
198+
|| name == "target"
199+
|| name == "node_modules"
200+
|| name == ".venv"
201+
|| name == "venv"
202+
|| name == ".idea"
203+
|| name == ".vscode"
204+
{
205+
return false;
206+
}
207+
true
208+
});
209+
210+
for entry in walker.filter_map(|e| e.ok()) {
193211
let path = entry.path();
194212

195213
// Only process files, not directories

0 commit comments

Comments
 (0)