Skip to content

Commit 693673b

Browse files
committed
perf(linter): reduce iterations when collecting directories for nested configs (#12329)
Small perf optimization. Presumably all paths will usually have the same prefix e.g.: * `/Users/bozo/projects/best-project-ever` * `/Users/bozo/projects/best-project-ever/src/components` * `/Users/bozo/projects/best-project-ever/src/server` When finding directories to search for nested configs, stop walking up to parent directories when find a directory that's already in the `HashSet`. We know that dir's parent, grandparent, etc will already be in the set too, so no need to check them again.
1 parent b36dc92 commit 693673b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

apps/oxlint/src/lint.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,10 @@ impl LintRunner {
445445
while let Some(dir) = current {
446446
// NOTE: Initial benchmarking showed that it was faster to iterate over the directories twice
447447
// rather than constructing the configs in one iteration. It's worth re-benchmarking that though.
448-
directories.insert(dir);
448+
let inserted = directories.insert(dir);
449+
if !inserted {
450+
break;
451+
}
449452
current = dir.parent();
450453
}
451454
}

0 commit comments

Comments
 (0)