Skip to contentSkip to conversation

Speed up commands that use rev-list when max-count is specified.

PATCH In review Benjamin C Meyer 4 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Speed up commands that use rev-list when max-count is specified.

Many command have code similar to the following:

while ((commit = get_revision(rev)) != NULL) { ... }

This results in and extra call to get_revision that first finds the next revision and then notices max-count is 0 and returns NULL. Adding a max-count check before any expensive work reduces the runtime of all of the commands the have this pattern.

Depending on the use case this can have a big impact on the running time.

---
 revision.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
revision.c +3 -0
index 490b484..4673d70 100644
@@ -2058,6 +2058,9 @@ static struct commit *get_revision_internal(struct rev_info *revs)
 
 struct commit *get_revision(struct rev_info *revs)
 {
+	if (revs->max_count == 0)
+		return NULL;
+
 	struct commit *c;
 	struct commit_list *reversed;
 
Signature · 1 line
1.7.0.2
#1 lore raw
Quoted 7 lines · Benjamin C Meyer

 struct commit *get_revision(struct rev_info *revs) {
+       if (revs->max_count == 0)
+               return NULL;
+
       struct commit *c;
       struct commit_list *reversed;

Declaring variables in the middle of a function is a C99 feature (and a GNU extension in C89 mode). I don't know if this is allowed in git code, but it would be easy enough to make this ANSI C89 compatible by putting your new statement after the variable declarations.

#2 lore raw
In reply to Benjamin C Meyer

Heya,

Quoted 1 line · Benjamin C Meyer

Depending on the use case this can have a big impact on the running time.

Sounds promising, do you have any numbers?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#3 lore raw

In the git repo a more extreme case doing something like git log -1 copy.c the patch will reduce the runtime by 70%. Running it on every top level file in git ('for f in *; log -1 $f; done') goes from 9 minutes to 8:30.

-Benjamin Meyer

Quoted 15 lines · Sverre Rabbelier

Heya,

Quoted 1 line · Benjamin C Meyer

Depending on the use case this can have a big impact on the running time.

Sounds promising, do you have any numbers?

Signature · 7 lines
Cheers,

Sverre Rabbelier
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html