Skip to content

Commit

Permalink
Fix poor performance when using --long
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TomLonergan03 committed Mar 11, 2024
1 parent 393baea commit 2f00a15
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tree/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2f00a15

Please sign in to comment.