Skip to content

Commit 815b679

Browse files
committed
dependencies: avoid canonicalization for missing files
Checks whether a file exists before canonicalizing. This is a significant speed up because canonicalizing walks the path from the root, which is much more likely to spend time randomly stat'ing files that end up not being relevant. This more than doubles (!) the speed of the program on my machine.
1 parent c07e3eb commit 815b679

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/dependencies/cparse.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ use tracing::{error, info, trace};
1414

1515
/// Attempt to make the full path of head::tail
1616
/// returns None if that fails (e.g. path does not exist)
17-
fn try_resolve(head: &Path, tail: &PathBuf) -> Option<PathBuf> {
17+
fn try_resolve(head: &Path, tail: &Path) -> Option<PathBuf> {
18+
let path = head.join(tail);
19+
if !path.exists() {
20+
return None;
21+
}
22+
1823
canonicalize_cached(head.join(tail)).ok()
1924
}
2025

0 commit comments

Comments
 (0)