From: Alan Cox Date: Mon, 12 Oct 2015 22:17:52 +0000 (+0100) Subject: ls: fix one stupid performance bug X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6c4be6cdb4d147c377b5e6faf670fb1c5a137126;p=FUZIX.git ls: fix one stupid performance bug No point doing a stat on each node when we don't actually need it ! We should chdir into the directory before doing the stats on the short path. That avoids all the name walking overhead and thrash. Likewise it might be sensible to stat in inode order and batched, but that may cost more than the saving ! --- diff --git a/Applications/util/ls.c b/Applications/util/ls.c index 71554078..7ec1ab61 100644 --- a/Applications/util/ls.c +++ b/Applications/util/ls.c @@ -1,4 +1,8 @@ /* The "ls" standard command. + * + * FIXME: we should chdir into the directory we are listing if doing stats + * and then stat the shortname (this saves lots of filename walks and the + * resulting touches of atime). */ #include #include @@ -324,7 +328,8 @@ void main(int argc, char *argv[]) /* Now finally list the filenames. */ for (i = 0; i < listused; i++, free(name)) { name = list[i]; - if (LSTAT(name, &statbuf) < 0) { + /* Only do expensive stat calls if we actually need the data ! */ + if ((flags & (LSF_DIR|LSF_FILE|LSF_INODE|LSF_LONG)) && LSTAT(name, &statbuf) < 0) { perror(name); continue; }