[Bug 3931] wildcard decimates directory listing performance (sftp ls)

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Tue Sep 15 18:13:12 AEST 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=3931

Damien Miller <djm at mindrot.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|NEW                         |RESOLVED
                 CC|                            |djm at mindrot.org

--- Comment #3 from Damien Miller <djm at mindrot.org> ---
> Why is the wildcard causing a stat on each file? (Can't it just
> check what is in the directory, and filter the results through
> a regex?)

That's not how either ls or sftp ls work.

The sftp protocol has no notion of globs, so it has to make a bunch of
roundtrips to retrieve the directory listing and test each entry
against the glob..

https://github.com/openssh/openssh-portable/blob/V_10_5/sftp.c#L967

We don't want to maintain our own glob(3) implementation, so we use one
from OpenBSD libc via some wrappers:

https://github.com/openssh/openssh-portable/blob/V_10_5/sftp-glob.c

The version we use has extensions over POSIX that allow retaining
struct stat information received during glob(3)'s work to avoid
refetching

https://github.com/openssh/openssh-portable/blob/V_10_5/openbsd-compat/glob.c

But a glob is always going to be significantly more work than just
reading a directory.

Maybe we could be faster if wrote out own glob implementation that
worked more locally, but I think that's too much code to maintain for
too little gain.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.
You are watching someone on the CC list of the bug.


More information about the openssh-bugs mailing list