Skip to content

Commit fef381e

Browse files
avargitster
authored andcommitted
send-email: lazily shell out to "git var"
Optimize git-send-email by only shelling out to "git var" if we need to. This is easily done by re-inventing our own small version of perl's Memoize module. I suppose I could just use Memoize itself, but in a subsequent patch I'll be micro-optimizing send-email's use of dependencies. Using Memoize is a measly extra 5-10 milliseconds, but as we'll see that'll end up mattering for us in the end. This brings the runtime of a plain "send-email" from around ~160-170ms to ~140m-150ms. The runtime of the tests is around the same, or around ~20s. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9264d29 commit fef381e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

git-send-email.perl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,18 @@ sub config_regexp {
588588
}
589589

590590
my ($repoauthor, $repocommitter);
591-
($repoauthor) = Git::ident_person(@repo, 'author');
592-
($repocommitter) = Git::ident_person(@repo, 'committer');
591+
{
592+
my %cache;
593+
my ($author, $committer);
594+
my $common = sub {
595+
my ($what) = @_;
596+
return $cache{$what} if exists $cache{$what};
597+
($cache{$what}) = Git::ident_person(@repo, $what);
598+
return $cache{$what};
599+
};
600+
$repoauthor = sub { $common->('author') };
601+
$repocommitter = sub { $common->('committer') };
602+
}
593603

594604
sub parse_address_line {
595605
return map { $_->format } Mail::Address->parse($_[0]);
@@ -777,7 +787,7 @@ sub get_patch_subject {
777787
or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!);
778788

779789

780-
my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
790+
my $tpl_sender = $sender || $repoauthor->() || $repocommitter->() || '';
781791
my $tpl_subject = $initial_subject || '';
782792
my $tpl_in_reply_to = $initial_in_reply_to || '';
783793
my $tpl_reply_to = $reply_to || '';
@@ -983,7 +993,7 @@ sub file_declares_8bit_cte {
983993
$sender =~ s/^\s+|\s+$//g;
984994
($sender) = expand_aliases($sender);
985995
} else {
986-
$sender = $repoauthor || $repocommitter || '';
996+
$sender = $repoauthor->() || $repocommitter->() || '';
987997
}
988998
989999
# $sender could be an already sanitized address
@@ -1132,7 +1142,7 @@ sub make_message_id {
11321142
$uniq = "$message_id_stamp-$message_id_serial";
11331143

11341144
my $du_part;
1135-
for ($sender, $repocommitter, $repoauthor) {
1145+
for ($sender, $repocommitter->(), $repoauthor->()) {
11361146
$du_part = extract_valid_address(sanitize_address($_));
11371147
last if (defined $du_part and $du_part ne '');
11381148
}

0 commit comments

Comments
 (0)