From 2f00a15deacda49248d0505badbbfca213bd65c4 Mon Sep 17 00:00:00 2001 From: Tom Lonergan Date: Fri, 8 Mar 2024 16:20:10 +0000 Subject: Fix poor performance when using --long Previously, the unix extended attributes are always read no matter what. This is not ideal, as it is very expensive to call for files which we will not display and leads to significantly (~80x with level = 2) worse runtimes recursing large directories. This is fixed by only calling `unix::Attrs::from` when it is a file which is going to be displayed. --- src/tree/node/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tree/node/mod.rs b/src/tree/node/mod.rs index b010469..a74270c 100644 --- a/src/tree/node/mod.rs +++ b/src/tree/node/mod.rs @@ -272,7 +272,9 @@ impl TryFrom<(DirEntry, &Context)> for Node { let inode = Inode::try_from(&metadata).ok(); #[cfg(unix)] - let unix_attrs = if ctx.long { + let unix_attrs = if ctx.long + && path.components().count() <= ctx.dir_canonical().components().count().saturating_add(ctx.level()) + { unix::Attrs::from((&metadata, &dir_entry)) } else { unix::Attrs::default() -- cgit v1.2.3