From: Jeff King Date: Mon, 08 Jun 2026 23:03:15 GMT Subject: Re: [PATCH] ls-files: filter pathspec before lstat Message-ID: <20260608230315.GC340696@coredump.intra.peff.net> In-Reply-To: On Mon, Jun 08, 2026 at 06:06:33AM -0700, Junio C Hamano wrote: > On Sun, Jun 7, 2026 at 11:40, Tamir Duberstein wrote: > > show_files() checks whether each index entry is deleted or modified > > before show_ce() applies the pathspec. prune_index() avoids most of this > > work for pathspecs with a common directory prefix, but a top-level name > > or leading wildcard leaves every entry to be checked. > > > > Match the pathspec before lstat() for the deleted and modified modes. > > Keep the later match in show_ce() so --error-unmatch is satisfied only > > by entries that are actually shown. > > Adding an extra early `match_pathspec()` check before making slow > system calls like `lstat()` makes sense, especially when most of the > index entries need to be skipped. But if most of them would match, > then we would end up doing the same match_pathspec() calls twice for > each path, and run lstat() anyway, so you may also be able to > construct a perf test that demonstrates a case where this approach > is not a clear win (or even degradation), perhaps? The patchspec matching is linear in the number of pathspecs, so it's easy to get quadratic-ish results by just asking about: git ls-files -- $(git ls-files) So that probably provides an easy regression demonstration for this patch. I don't know how much it matters in the real world. That command is _already_ slow, and mostly people don't care that much. Long ago I had patches to build a trie of literal pathspecs, with the intent that blame-tree/last-modified could use the pathspec mechanism, but ultimately we took the code in a different direction. And nobody really complained about it since. ;) -Peff