# git-annotate efficiency

4 messages from 2006-02-24 to 2006-02-24. Participants: Morten Welinder, Randal L. Schwartz, Ryan Anderson.
Thread: https://gitlist.dev/t/3455

## Morten Welinder, 2006-02-24 15:37

Subject: git-annotate efficiency
Message-ID: <118833cc0602240737i42acdc90sb8f93dde1a1bc035@mail.gmail.com>
URL: https://gitlist.dev/e/118833cc0602240737i42acdc90sb8f93dde1a1bc035%40mail.gmail.com

```
So I wanted to give git-annotate a spin and typed...

    git annotate Makefile

Bad idea.  It's been ten minutes and no output yet.  While the script only
appears to use ~20% of cpu according to top, an strace shows that it
spins off a huge number of very short-lived subprocesses.

Morten




...
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
waitpid(1539, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 1539
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigaction(SIGHUP, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL}, NULL, 8) = 0
pipe([3, 4])                            = 0
pipe([5, 6])                            = 0
clone(child_stack=0,
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0x401db708) = 1540
close(6)                                = 0
close(4)                                = 0
read(5, "", 4)                          = 0
close(5)                                = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfffc718) = -1 EINVAL
(Invalid argument)
_llseek(3, 0, 0xbfffc760, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
read(3, "diff --git a/Makefile b/Makefile"..., 4096) = 63
read(3, "--- a/Makefile\n+++ b/Makefile\n@@"..., 4096) = 203
--- SIGCHLD (Child exited) @ 0 (0) ---
read(3, "", 4096)                       = 0
close(3)                                = 0
rt_sigaction(SIGHUP, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
...

```

## Morten Welinder, 2006-02-24 18:00

Subject: Re: git-annotate efficiency
Message-ID: <118833cc0602241000p4e4c8017u3e3afe76fbbd75a4@mail.gmail.com>
URL: https://gitlist.dev/e/118833cc0602241000p4e4c8017u3e3afe76fbbd75a4%40mail.gmail.com
In-Reply-To: <118833cc0602240737i42acdc90sb8f93dde1a1bc035@mail.gmail.com>

```
It looks like handle_rev is seeing the same revisions over and over again.
I don't know why that would be, but the following patch just skips dups.
I have no idea if it is right, though.

Morten


diff --git a/git-annotate.perl b/git-annotate.perl
index 3800c46..a5e2d86 100755
--- a/git-annotate.perl
+++ b/git-annotate.perl
@@ -117,7 +117,10 @@ sub init_claim {

 sub handle_rev {
        my $i = 0;
+       my %seen = ();
        while (my $rev = shift @revqueue) {
+               next if $seen{$rev};
+               $seen{$rev} = 1;

                my %revinfo = git_commit_info($rev);

```

## Randal L. Schwartz, 2006-02-24 19:06

Subject: Re: git-annotate efficiency
Message-ID: <86oe0wbmqn.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86oe0wbmqn.fsf%40blue.stonehenge.com
In-Reply-To: <118833cc0602241000p4e4c8017u3e3afe76fbbd75a4@mail.gmail.com>

```
>>>>> "Morten" == Morten Welinder <mwelinder@gmail.com> writes:

Morten> It looks like handle_rev is seeing the same revisions over and over again.
Morten> I don't know why that would be, but the following patch just skips dups.
Morten> I have no idea if it is right, though.

Morten> Morten


Morten> diff --git a/git-annotate.perl b/git-annotate.perl
Morten> index 3800c46..a5e2d86 100755
Morten> --- a/git-annotate.perl
Morten> +++ b/git-annotate.perl
Morten> @@ -117,7 +117,10 @@ sub init_claim {

Morten>  sub handle_rev {
Morten>         my $i = 0;
Morten> +       my %seen = ();
Morten>         while (my $rev = shift @revqueue) {
Morten> +               next if $seen{$rev};
Morten> +               $seen{$rev} = 1;

Morten>                 my %revinfo = git_commit_info($rev);

The traditional idiom for that is

        next if $seen{$rev}++;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

```

## Ryan Anderson, 2006-02-24 19:42

Subject: Re: git-annotate efficiency
Message-ID: <20060224194231.GA18691@mythryan2.michonline.com>
URL: https://gitlist.dev/e/20060224194231.GA18691%40mythryan2.michonline.com
In-Reply-To: <118833cc0602241000p4e4c8017u3e3afe76fbbd75a4@mail.gmail.com>

```
On Fri, Feb 24, 2006 at 01:00:24PM -0500, Morten Welinder wrote:
> It looks like handle_rev is seeing the same revisions over and over again.
> I don't know why that would be, but the following patch just skips dups.
> I have no idea if it is right, though.

Merges.

a--b--c--d--f
   \-g--h--/

It would do f,d,c,b,a + f,h,g,b,a

So yes, this fix is correct, and Junio, I'll be doing some changes this
weekend and send it along with a few other things.

(On a medium-sized test tree at work with 3500 commits in the tree, 37
on the main Makefile (6 merges), this cuts the annotate time from 10s to a little
over 2, so it's, umm, very worthwhile.)

> 
> Morten
> 
> 
> diff --git a/git-annotate.perl b/git-annotate.perl
> index 3800c46..a5e2d86 100755
> --- a/git-annotate.perl
> +++ b/git-annotate.perl
> @@ -117,7 +117,10 @@ sub init_claim {
> 
>  sub handle_rev {
>         my $i = 0;
> +       my %seen = ();
>         while (my $rev = shift @revqueue) {
> +               next if $seen{$rev};
> +               $seen{$rev} = 1;
> 
>                 my %revinfo = git_commit_info($rev);
> -
> 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
> 

-- 

Ryan Anderson
  sometimes Pug Majere

```
