diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-05-28 11:23:46 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-28 18:38:07 +0900 |
commit | fef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00 (patch) | |
tree | 9632ebec360b77af28e9bcf33d3e585c97ccea71 | |
parent | send-email: lazily load config for a big speedup (diff) | |
download | tgif-fef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00.tar.xz |
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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | git-send-email.perl | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/git-send-email.perl b/git-send-email.perl index de62cbf250..38408ec75a 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -588,8 +588,18 @@ if (0) { } my ($repoauthor, $repocommitter); -($repoauthor) = Git::ident_person(@repo, 'author'); -($repocommitter) = Git::ident_person(@repo, 'committer'); +{ + my %cache; + my ($author, $committer); + my $common = sub { + my ($what) = @_; + return $cache{$what} if exists $cache{$what}; + ($cache{$what}) = Git::ident_person(@repo, $what); + return $cache{$what}; + }; + $repoauthor = sub { $common->('author') }; + $repocommitter = sub { $common->('committer') }; +} sub parse_address_line { return map { $_->format } Mail::Address->parse($_[0]); @@ -777,7 +787,7 @@ if ($compose) { or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!); - my $tpl_sender = $sender || $repoauthor || $repocommitter || ''; + my $tpl_sender = $sender || $repoauthor->() || $repocommitter->() || ''; my $tpl_subject = $initial_subject || ''; my $tpl_in_reply_to = $initial_in_reply_to || ''; my $tpl_reply_to = $reply_to || ''; @@ -983,7 +993,7 @@ if (defined $sender) { $sender =~ s/^\s+|\s+$//g; ($sender) = expand_aliases($sender); } else { - $sender = $repoauthor || $repocommitter || ''; + $sender = $repoauthor->() || $repocommitter->() || ''; } # $sender could be an already sanitized address @@ -1132,7 +1142,7 @@ sub make_message_id { $uniq = "$message_id_stamp-$message_id_serial"; my $du_part; - for ($sender, $repocommitter, $repoauthor) { + for ($sender, $repocommitter->(), $repoauthor->()) { $du_part = extract_valid_address(sanitize_address($_)); last if (defined $du_part and $du_part ne ''); } |