Skip to content

Commit 2e26454

Browse files
authored
df: improve perfs (uutils#10122)
* df: fix O(n²) performance in deeply nested directories by checking is_absolute() before is_symlink() * add "sysfs" to the spell-checker ignore
1 parent 30239e6 commit 2e26454

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/uu/df/src/df.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
// spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs
5+
// spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs sysfs
66
mod blocks;
77
mod columns;
88
mod filesystem;
@@ -311,7 +311,11 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
311311
// but `vmi` is probably not very long in practice.
312312
if is_included(&mi, opt) && is_best(&mounts, &mi) {
313313
let dev_path: &Path = Path::new(&mi.dev_name);
314-
if dev_path.is_symlink() {
314+
// Only check is_symlink() for absolute paths. For non-absolute paths
315+
// like "tmpfs", "sysfs", etc., is_symlink() would resolve relative to
316+
// the current working directory, which is extremely slow in deeply
317+
// nested directories (O(n) syscalls where n is the directory depth).
318+
if dev_path.is_absolute() && dev_path.is_symlink() {
315319
if let Ok(canonicalized_symlink) = uucore::fs::canonicalize(
316320
dev_path,
317321
uucore::fs::MissingHandling::Existing,

0 commit comments

Comments
 (0)