git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Gregory Anders" <greg@gpanders.com>,
	"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Eric Wong" <e@80x24.org>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 03/10] send-email: lazily load config for a big speedup
Date: Thu, 20 May 2021 10:19:00 +0200	[thread overview]
Message-ID: <patch-03.10-1b27a393ae3-20210520T081826Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.10-00000000000-20210520T081826Z-avarab@gmail.com>

Reduce the time it takes git-send-email to get to even the most
trivial of tasks (such as serving up its "-h" output) by first listing
config keys that exist, and only then only call e.g. "git config
--bool" on them if they do.

Over a lot of runs this speeds the time to "-h" up for me from ~250ms
to ~150ms, and the runtime of t9001-send-email.sh goes from ~25s to
~20s.

This introduces a race condition where we'll do the "wrong" thing if a
config key were to be inserted between us discovering the list and
calling read_config(), i.e. we won't know about the racily added
key. In theory this is a change in behavior, in practice it doesn't
matter.

The config_regexp() function being changed here was added in
dd84e528a34 (git-send-email: die if sendmail.* config is set,
2020-07-23) for use by git-send-email. So we can change its odd return
value in the case where no values are found by "git config". The
difference in the *.pm code would matter if it was invoked in scalar
context, but now it no longer is.

Arguably this caching belongs in Git.pm itself, but in lieu of
modifying it for all its callers let's only do this for "git
send-email". The other big potential win would be "git svn", but
unlike "git send-email" it doesn't check tens of config variables one
at a time at startup (in my brief testing it doesn't check any).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-send-email.perl | 35 ++++++++++++++++++++++++++---------
 perl/Git.pm         |  4 ++--
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index f9d859da3ed..5b0b7c33ec6 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -337,11 +337,13 @@ sub signal_handler {
 
 # Read our sendemail.* config
 sub read_config {
-	my ($configured, $prefix) = @_;
+	my ($known_keys, $configured, $prefix) = @_;
 
 	foreach my $setting (keys %config_bool_settings) {
 		my $target = $config_bool_settings{$setting};
-		my $v = Git::config_bool(@repo, "$prefix.$setting");
+		my $key = "$prefix.$setting";
+		next unless exists $known_keys->{$key};
+		my $v = Git::config_bool(@repo, $key);
 		next unless defined $v;
 		next if $configured->{$setting}++;
 		$$target = $v;
@@ -349,8 +351,10 @@ sub read_config {
 
 	foreach my $setting (keys %config_path_settings) {
 		my $target = $config_path_settings{$setting};
+		my $key = "$prefix.$setting";
+		next unless exists $known_keys->{$key};
 		if (ref($target) eq "ARRAY") {
-			my @values = Git::config_path(@repo, "$prefix.$setting");
+			my @values = Git::config_path(@repo, $key);
 			next unless @values;
 			next if $configured->{$setting}++;
 			@$target = @values;
@@ -365,14 +369,16 @@ sub read_config {
 
 	foreach my $setting (keys %config_settings) {
 		my $target = $config_settings{$setting};
+		my $key = "$prefix.$setting";
+		next unless exists $known_keys->{$key};
 		if (ref($target) eq "ARRAY") {
-			my @values = Git::config(@repo, "$prefix.$setting");
+			my @values = Git::config(@repo, $key);
 			next unless @values;
 			next if $configured->{$setting}++;
 			@$target = @values;
 		}
 		else {
-			my $v = Git::config(@repo, "$prefix.$setting");
+			my $v = Git::config(@repo, $key);
 			next unless defined $v;
 			next if $configured->{$setting}++;
 			$$target = $v;
@@ -380,9 +386,20 @@ sub read_config {
 	}
 }
 
+# Save ourselves a lot of work of shelling out to 'git config' (it
+# parses 'bool' etc.) by only doing so for config keys that exist.
+my %known_config_keys;
+{
+	my @known_config_keys = Git::config_regexp("^sende?mail[.]");
+	@known_config_keys{@known_config_keys} = ();
+}
+
 # sendemail.identity yields to --identity. We must parse this
 # special-case first before the rest of the config is read.
-$identity = Git::config(@repo, "sendemail.identity");
+{
+	my $key = "sendemail.identity";
+	$identity = Git::config(@repo, $key) if exists $known_config_keys{$key};
+}
 my $rc = GetOptions(
 	"identity=s" => \$identity,
 	"no-identity" => \$no_identity,
@@ -393,8 +410,8 @@ sub read_config {
 # Now we know enough to read the config
 {
     my %configured;
-    read_config(\%configured, "sendemail.$identity") if defined $identity;
-    read_config(\%configured, "sendemail");
+    read_config(\%known_config_keys, \%configured, "sendemail.$identity") if defined $identity;
+    read_config(\%known_config_keys, \%configured, "sendemail");
 }
 
 # Begin by accumulating all the variables (defined above), that we will end up
@@ -478,7 +495,7 @@ sub read_config {
     usage();
 }
 
-if ($forbid_sendmail_variables && (scalar Git::config_regexp("^sendmail[.]")) != 0) {
+if ($forbid_sendmail_variables && grep { /^sendmail/s } keys %known_config_keys) {
 	die __("fatal: found configuration options for 'sendmail'\n" .
 		"git-send-email is configured with the sendemail.* options - note the 'e'.\n" .
 		"Set sendemail.forbidSendmailVariables to false to disable this check.\n");
diff --git a/perl/Git.pm b/perl/Git.pm
index 73ebbf80cc6..06a10b175a7 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -754,8 +754,8 @@ sub config_regexp {
 	} catch Git::Error::Command with {
 		my $E = shift;
 		if ($E->value() == 1) {
-			my @matches = ();
-			return @matches;
+			# Key(s) not found.
+			return;
 		} else {
 			throw $E;
 		}
-- 
2.32.0.rc0.405.g5d387561bb3


  parent reply	other threads:[~2021-05-20  8:19 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 13:48 [PATCH 0/9] send-email: various optimizations to speed up by >2x Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 1/9] send-email: remove non-working support for "sendemail.smtpssl" Ævar Arnfjörð Bjarmason
2021-05-12 15:46   ` Đoàn Trần Công Danh
2021-05-12 13:48 ` [PATCH 2/9] send-email: refactor sendemail.smtpencryption config parsing Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 3/9] send-email: lazily load config for a big speedup Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 4/9] send-email: lazily shell out to "git var" Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 5/9] send-email: use function syntax instead of barewords Ævar Arnfjörð Bjarmason
2021-05-12 23:11   ` Jeff King
2021-05-12 13:48 ` [PATCH 6/9] send-email: get rid of indirect object syntax Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 7/9] send-email: lazily load modules for a big speedup Ævar Arnfjörð Bjarmason
2021-05-12 13:48 ` [PATCH 8/9] perl: lazily load some common Git.pm setup code Ævar Arnfjörð Bjarmason
2021-05-12 18:05   ` Eric Wong
2021-05-12 13:48 ` [PATCH 9/9] send-email: move trivial config handling to Perl Ævar Arnfjörð Bjarmason
2021-05-12 19:52   ` Eric Sunshine
2021-05-12 23:08   ` Jeff King
2021-05-13  7:04     ` Felipe Contreras
2021-05-13  7:07       ` Ævar Arnfjörð Bjarmason
2021-05-13  7:26       ` Jeff King
2021-05-13  8:15         ` Felipe Contreras
2021-05-13 11:45           ` Ævar Arnfjörð Bjarmason
2021-05-12 18:04 ` [PATCH 0/9] send-email: various optimizations to speed up by >2x Eric Wong
2021-05-12 23:34 ` Jeff King
2021-05-12 23:36 ` Jeff King
2021-05-13  7:37   ` Ævar Arnfjörð Bjarmason
2021-05-13  7:49     ` Jeff King
2021-05-20  8:18 ` [PATCH v2 00/10] " Ævar Arnfjörð Bjarmason
2021-05-20  8:18   ` [PATCH v2 01/10] send-email: remove non-working support for "sendemail.smtpssl" Ævar Arnfjörð Bjarmason
2021-05-20  8:18   ` [PATCH v2 02/10] send-email: refactor sendemail.smtpencryption config parsing Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` Ævar Arnfjörð Bjarmason [this message]
2021-05-20  8:19   ` [PATCH v2 04/10] send-email: lazily shell out to "git var" Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 05/10] send-email: use function syntax instead of barewords Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 06/10] send-email: get rid of indirect object syntax Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 07/10] send-email: lazily load modules for a big speedup Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 08/10] perl: lazily load some common Git.pm setup code Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 09/10] send-email: move trivial config handling to Perl Ævar Arnfjörð Bjarmason
2021-05-20  8:19   ` [PATCH v2 10/10] perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd() Ævar Arnfjörð Bjarmason
2021-05-20  8:27   ` [PATCH v2 00/10] send-email: various optimizations to speed up by >2x Jeff King
2021-05-20 23:53     ` Junio C Hamano
2021-05-21  6:23       ` Ævar Arnfjörð Bjarmason
2021-05-21  7:07         ` Junio C Hamano
2021-05-21  9:13         ` Jeff King
2021-05-21  9:24           ` Ævar Arnfjörð Bjarmason
2021-05-21  9:37             ` Jeff King
2021-05-28 15:49         ` Felipe Contreras
2021-05-29  8:19           ` Ævar Arnfjörð Bjarmason
2021-05-29 14:53             ` Felipe Contreras
2021-05-30 11:33               ` Ævar Arnfjörð Bjarmason
2021-05-30 16:07                 ` Felipe Contreras
2021-05-28 15:12     ` Felipe Contreras
2021-05-23  8:56   ` [PATCH v3 00/13] " Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 01/13] send-email tests: support GIT_TEST_PERL_FATAL_WARNINGS=true Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 02/13] send-email tests: test for boolean variables without a value Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 03/13] send-email: remove non-working support for "sendemail.smtpssl" Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 04/13] send-email: refactor sendemail.smtpencryption config parsing Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 05/13] send-email: copy "config_regxp" into git-send-email.perl Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 06/13] send-email: lazily load config for a big speedup Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 07/13] send-email: lazily shell out to "git var" Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 08/13] send-email: use function syntax instead of barewords Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 09/13] send-email: get rid of indirect object syntax Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 10/13] send-email: lazily load modules for a big speedup Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 11/13] perl: lazily load some common Git.pm setup code Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 12/13] send-email: move trivial config handling to Perl Ævar Arnfjörð Bjarmason
2021-05-23  8:56     ` [PATCH v3 13/13] perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd() Ævar Arnfjörð Bjarmason
2021-05-24  1:15     ` [PATCH v3 00/13] send-email: various optimizations to speed up by >2x Junio C Hamano
2021-05-24  7:52     ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 01/13] send-email tests: support GIT_TEST_PERL_FATAL_WARNINGS=true Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 02/13] send-email tests: test for boolean variables without a value Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 03/13] send-email: remove non-working support for "sendemail.smtpssl" Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 04/13] send-email: refactor sendemail.smtpencryption config parsing Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 05/13] send-email: copy "config_regxp" into git-send-email.perl Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 06/13] send-email: lazily load config for a big speedup Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 07/13] send-email: lazily shell out to "git var" Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 08/13] send-email: use function syntax instead of barewords Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 09/13] send-email: get rid of indirect object syntax Ævar Arnfjörð Bjarmason
2021-05-24  7:52       ` [PATCH v4 10/13] send-email: lazily load modules for a big speedup Ævar Arnfjörð Bjarmason
2021-05-27  1:11         ` Junio C Hamano
2021-05-27 11:36           ` Ævar Arnfjörð Bjarmason
2021-05-24  7:53       ` [PATCH v4 11/13] perl: lazily load some common Git.pm setup code Ævar Arnfjörð Bjarmason
2021-05-24  7:53       ` [PATCH v4 12/13] send-email: move trivial config handling to Perl Ævar Arnfjörð Bjarmason
2021-05-27 15:57         ` Jeff King
2021-05-24  7:53       ` [PATCH v4 13/13] perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd() Ævar Arnfjörð Bjarmason
2021-05-27 16:00       ` [PATCH v4 00/13] send-email: various optimizations to speed up by >2x Jeff King
2021-05-28  9:23       ` [PATCH v5 " Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 01/13] send-email tests: support GIT_TEST_PERL_FATAL_WARNINGS=true Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 02/13] send-email tests: test for boolean variables without a value Ævar Arnfjörð Bjarmason
2021-07-10 23:23           ` Jeff King
2021-05-28  9:23         ` [PATCH v5 03/13] send-email: remove non-working support for "sendemail.smtpssl" Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 04/13] send-email: refactor sendemail.smtpencryption config parsing Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 05/13] send-email: copy "config_regxp" into git-send-email.perl Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 06/13] send-email: lazily load config for a big speedup Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 07/13] send-email: lazily shell out to "git var" Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 08/13] send-email: use function syntax instead of barewords Ævar Arnfjörð Bjarmason
2021-05-28 16:10           ` Felipe Contreras
2021-05-29  8:17             ` Ævar Arnfjörð Bjarmason
2021-05-29 14:25               ` Felipe Contreras
2021-05-28  9:23         ` [PATCH v5 09/13] send-email: get rid of indirect object syntax Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 10/13] send-email: lazily load modules for a big speedup Ævar Arnfjörð Bjarmason
2021-05-28 15:55           ` Felipe Contreras
2021-05-29  8:12             ` Ævar Arnfjörð Bjarmason
2021-05-29 14:24               ` Felipe Contreras
2021-05-28  9:23         ` [PATCH v5 11/13] perl: lazily load some common Git.pm setup code Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 12/13] send-email: move trivial config handling to Perl Ævar Arnfjörð Bjarmason
2021-05-28  9:23         ` [PATCH v5 13/13] perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd() Ævar Arnfjörð Bjarmason
2021-05-28 16:13         ` [PATCH v5 00/13] send-email: various optimizations to speed up by >2x Felipe Contreras
2021-05-31  5:48         ` Jeff King
2021-05-31  9:53           ` Ævar Arnfjörð Bjarmason
2021-05-31 14:38             ` Jeff King
2021-05-27  7:21 ` [PATCH 0/9] " Elijah Newren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-03.10-1b27a393ae3-20210520T081826Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=congdanhqx@gmail.com \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=greg@gpanders.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).