# [PATCH] Speed up commands that use rev-list when max-count is specified.

4 messages from 2010-03-21 to 2010-03-21. Participants: Benjamin C Meyer, Sverre Rabbelier, Mark Lodato, Benjamin Meyer.
Thread: https://gitlist.dev/t/23116

## Benjamin C Meyer, 2010-03-21 03:31

Subject: [PATCH] Speed up commands that use rev-list when max-count is specified.
Message-ID: <1269142267-17127-1-git-send-email-bmeyer@rim.com>
URL: https://gitlist.dev/e/1269142267-17127-1-git-send-email-bmeyer%40rim.com

```
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.

Signed-off-by: Benjamin C Meyer <bmeyer@rim.com>
---
 revision.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/revision.c b/revision.c
index 490b484..4673d70 100644
--- a/revision.c
+++ b/revision.c
@@ -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;
 
-- 
1.7.0.2

```

## Sverre Rabbelier, 2010-03-21 11:12

Subject: Re: [PATCH] Speed up commands that use rev-list when max-count is specified.
Message-ID: <fabb9a1e1003210412n58a3b951x1de4543f11b888c4@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e1003210412n58a3b951x1de4543f11b888c4%40mail.gmail.com
In-Reply-To: <1269142267-17127-1-git-send-email-bmeyer@rim.com>

```
Heya,

On Sun, Mar 21, 2010 at 04:31, Benjamin C Meyer <bmeyer@rim.com> wrote:
> Depending on the use case this can have a big impact on the running time.

Sounds promising, do you have any numbers?

-- 
Cheers,

Sverre Rabbelier

```

## Mark Lodato, 2010-03-21 14:09

Subject: Re: [PATCH] Speed up commands that use rev-list when max-count is specified.
Message-ID: <ca433831003210709k1da46c8docfdac358253625e@mail.gmail.com>
URL: https://gitlist.dev/e/ca433831003210709k1da46c8docfdac358253625e%40mail.gmail.com
In-Reply-To: <1269142267-17127-1-git-send-email-bmeyer@rim.com>

```
On Sat, Mar 20, 2010 at 11:31 PM, Benjamin C Meyer <bmeyer@rim.com> wrote:
>  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.

```

## Benjamin Meyer, 2010-03-21 16:57

Subject: Re: [PATCH] Speed up commands that use rev-list when max-count is specified.
Message-ID: <10BD5DAD-16FB-40FB-A77B-955EA0ECD4CB@meyerhome.net>
URL: https://gitlist.dev/e/10BD5DAD-16FB-40FB-A77B-955EA0ECD4CB%40meyerhome.net
In-Reply-To: <fabb9a1e1003210412n58a3b951x1de4543f11b888c4@mail.gmail.com>

```
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

On Mar 21, 2010, at 7:12 AM, Sverre Rabbelier wrote:

> Heya,
> 
> On Sun, Mar 21, 2010 at 04:31, Benjamin C Meyer <bmeyer@rim.com> wrote:
>> Depending on the use case this can have a big impact on the running time.
> 
> Sounds promising, do you have any numbers?
> 
> -- 
> Cheers,
> 
> Sverre Rabbelier
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```
