git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] ls-files: filter pathspec before lstat

From
Jeff King <peff@peff.net>
Date
Jun 11, 2026, 08:41 UTC
Message-ID
<20260611084132.GK2191159@coredump.intra.peff.net>
In-Reply-To
<CAJ-ks9mJk-=xp1hW77hAoZwwQAfpMukYO8OvvkLx646-2Z3_kg@mail.gmail.com>
On Tue, Jun 09, 2026 at 04:15:41PM -0700, Tamir Duberstein wrote:
Show 29 quoted lines
> On Tue, Jun 9, 2026 at 3:41 AM Jeff King <peff@peff.net> wrote:
> >
> > On Mon, Jun 08, 2026 at 07:37:15PM -0700, Tamir Duberstein wrote:
> >
> > > +             /*
> > > +              * match_pathspec() is linear in pathspec.nr, so prefilter only
> > > +              * the single-pathspec case. Only entries shown by show_ce()
> > > +              * satisfy --error-unmatch.
> > > +              */
> > > +             if (pathspec.nr == 1 &&
> > > +                 !match_pathspec(repo->index, &pathspec, fullname.buf,
> > > +                                 fullname.len, max_prefix_len, NULL,
> > > +                                 S_ISDIR(ce->ce_mode) ||
> > > +                                 S_ISGITLINK(ce->ce_mode)))
> > > +                     continue;
> >
> > This feels...kind of arbitrary, no? Surely it's also faster with
> > pathspec.nr == 2, and so on up to some nr closer to the size of the
> > total index. It feels weird to be making an arbitrary cutoff based on
> > pathspec performance in calling code like this.
> >
> > It is not wrong, per se, as you are optimizing your case without trying
> > to hurt any others. But what do we do when somebody profiles it and
> > comes along trying to bump the number to 2, or 10?
> >
> > I dunno.
> 
> Yeah, absolutely it's arbitrary. The simplest answer is that others
> are welcome to bump this, provided they make the case for it.

OK. I can live with, I suppose, but I am tempted to say that it should just kick in always (i.e., removing the pathspec.nr check).

Though I did show a case where the performance regresses, it was pretty made-up and not something I'd expect in the real world. And you'd see that same crappy performance with "git ls-files -- $(git ls-files)", without the "-m". The real solution is making the pathspec code less crappy.

-Peff
Previous: Tamir DubersteinNext: Tamir Duberstein
Message 8 of 12 in “ls-files: filter pathspec before lstat”
  1. ls-files: filter pathspec before lstatTamir Duberstein, Jun 9, 2026
  2. Junio C HamanoJun 9, 2026
  3. Tamir DubersteinJun 9, 2026
  4. Junio C HamanoJun 9, 2026
  5. Tamir DubersteinJun 9, 2026
  6. Jeff KingJun 9, 2026
  7. Tamir DubersteinJun 9, 2026
  8. Jeff KingJun 11, 2026
  9. Tamir DubersteinJun 11, 2026
  10. Junio C HamanoJun 11, 2026
  11. ls-files: filter pathspec before lstatTamir Duberstein, Jun 12, 2026
  12. Junio C HamanoJun 15, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.