Subject: Re: [PATCH v6 1/1] builtin/grep.c: integrate with sparse index

From: Junio C Hamano <[email-masked]>
Date: Fri, 23 Sep 2022 09:40:18 -0700

Shaoxuan Yuan <[email-masked]> writes:

> - Command used for testing:
>
> 	git grep --cached bogus -- "f2/f1/f1/*"
>
> The reason for specifying a pathspec is that, if we don't specify a
> pathspec, then grep_tree() will walk all the trees and blobs to find the
> pattern, and the time consumed doing so is not too different from using
> the original ensure_full_index() method, which also spends most of the
> time walking trees. However, when a pathspec is specified, this latest
> logic will only walk the area of trees enclosed by the pathspec, and the
> time consumed is reasonably a lot less.

Good.  So without pathspec, we lazily populate the index and catch
matches even from outside the sparse cone.  We punt to "implicitly"
apply the sparse cone(s) as a pathspec that limits the hits to the
paths in the sparse cone(s).

> That is, if we don't specify a pathspec, the performance difference [1]
> is indistinguishable: both methods walk all the trees and take generally
> same amount of time (even with the index construction time included for
> ensure_full_index()).

Good.