threads / rfc / 34534

[RFC] Faster git grep.

Subject: [RFC] Faster git grep.

## tl;dr

6 messages between Jul 25, 2013 and Jul 26, 2013.

replies: 5people: 3as markdown or json

Ondřej Bílka· Jul 25, 2013, 18:29 UTC · lore
Hi, 

When I do git grep then with big codebase (gcc) it executes slowly. I am thinking to add option to speed up search time.

One solution would be to use same trick as was done in google code. Build and keep database of trigraphs and which files contain how many of them. When querry is made then check only these files that have appropriate combination of trigraphs.

Updating database would be relatively inexpensive compared to disk access we need to do anyway.

A space usage might be problem so which is why I decided go option route.

Comments, pointers?
Ondra
Jeff King· Jul 25, 2013, 20:08 UTC · re: Ondřej Bílka · lore

Re: [RFC] Faster git grep.

On Thu, Jul 25, 2013 at 08:29:05PM +0200, Ondřej Bílka wrote:
> One solution would be to use same trick as was done in google code.
> Build and keep database of trigraphs and which files contain how many of
> them. When querry is made then check
> only these files that have appropriate combination of trigraphs.
That seems like a sensible approach.
> Updating database would be relatively inexpensive compared to disk
> access we need to do anyway.

Yes, I think it can be quite cheap, since you would only need to re-index files that have changed (and git is very quick at telling you what those files are).

> A space usage might be problem so which is why I decided go option
> route.
> 
> Comments, pointers?

I think it is a good idea, but not need to be part of core git. It seems more like you would want to glue together an existing code-indexing solution (like codesearch) with git (which would provide the list of files to index and to search).

If that proves useful in practice, but the interface is clunky for whatever reason, then a good follow-on project could be to build support for updating and using the index via the usual "git grep".

-Peff
Junio C Hamano· Jul 25, 2013, 20:41 UTC · re: Ondřej Bílka · lore

Re: [RFC] Faster git grep.

Ondřej Bílka <neleai@seznam.cz> writes:
> One solution would be to use same trick as was done in google code. 
> Build and keep database of trigraphs and which files contain how many of
> them. When querry is made then check
> only these files that have appropriate combination of trigraphs.

This depends on how you go about trying to reducing the database overhead, I think. For example, a very naive approach would be to create such trigraph hit index for each and every commit for all paths. When "git grep $commit $pattern" is run, you would consult such table with $commit and potential trigraphs derived from the $pattern to grab the potential paths your hits _might_ be in.

But the contents of a path usually do not change in each and every commit. So you may want to instead index with the blob object names (i.e. which trigraphs appear in what blobs). But once you go that route, your "git grep $commit $pattern" needs to read and enumerate all the blobs that appear in $commit's tree, and see which blobs may potentially have hits. Then you would need to build an index every time you make a new commit for blobs whose trigraphs have not been counted.

Nice thing is that once a blob (or a commit for that matter) is created and its object name is known, its contents will not change, so you can index once and reuse it many times. But I am not yet convinced if pre-indexing is an overall win, compared to the cost of maintaining such a database.

Ondřej Bílka· Jul 25, 2013, 21:31 UTC · re: Junio C Hamano · lore

Re: [RFC] Faster git grep.

On Thu, Jul 25, 2013 at 01:41:13PM -0700, Junio C Hamano wrote:
Show 14 quoted lines
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > One solution would be to use same trick as was done in google code. 
> > Build and keep database of trigraphs and which files contain how many of
> > them. When querry is made then check
> > only these files that have appropriate combination of trigraphs.
> 
> This depends on how you go about trying to reducing the database
> overhead, I think.  For example, a very naive approach would be to
> create such trigraph hit index for each and every commit for all
> paths.  When "git grep $commit $pattern" is run, you would consult
> such table with $commit and potential trigraphs derived from the
> $pattern to grab the potential paths your hits _might_ be in.
>

Do you think that git grep $commit $pattern is run in more than 1% of cases than git grep $pattern ?

If grepping random commit in history is important use case then keeping db information in history makes sense. Otherwise just having database for current version and updating it on the fly as version changes is enough.

Show 14 quoted lines
> But the contents of a path usually do not change in each and every
> commit.  So you may want to instead index with the blob object names
> (i.e. which trigraphs appear in what blobs).  But once you go that
> route, your "git grep $commit $pattern" needs to read and enumerate
> all the blobs that appear in $commit's tree, and see which blobs may
> potentially have hits.  Then you would need to build an index every
> time you make a new commit for blobs whose trigraphs have not been
> counted.
> 
> Nice thing is that once a blob (or a commit for that matter) is
> created and its object name is known, its contents will not change,
> so you can index once and reuse it many times.  But I am not yet
> convinced if pre-indexing is an overall win, compared to the cost of
> maintaining such a database.
Junio C Hamano· Jul 26, 2013, 01:28 UTC · re: Ondřej Bílka · lore

Re: [RFC] Faster git grep.

Ondřej Bílka <neleai@seznam.cz> writes:
> If grepping random commit in history is important use case then keeping
> db information in history makes sense. Otherwise just having database
> for current version and updating it on the fly as version changes is
> enough.

Will you reindex every time I do "git checkout next; git checkout master"?

Ondřej Bílka· Jul 26, 2013, 05:45 UTC · re: Junio C Hamano · lore

Re: [RFC] Faster git grep.

On Thu, Jul 25, 2013 at 06:28:50PM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > If grepping random commit in history is important use case then keeping
> > db information in history makes sense. Otherwise just having database
> > for current version and updating it on the fly as version changes is
> > enough.
> 
> Will you reindex every time I do "git checkout next; git checkout
> master"?

This is separate issue as you would need to change index anyway, number of changes would be proportionate to size of diff so you would not gain much. Possible problem here is that you would end changing many files. A possible solution is do rebuilding in background.

For switching often to different branches that are vastly different a best solution for me seems to keep separate index for each branch.

Also data structure is trigraph: list of files with counts.

← back to recent threads