unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/2] lei: short-lived sub reductions
@ 2024-11-26 21:29 Eric Wong
  2024-11-26 21:29 ` [PATCH 1/2] import: allow $noisy toggle, simplify `lei rediff' Eric Wong
  2024-11-26 21:29 ` [PATCH 2/2] lei: avoid repeatedly recreating anonymous subs Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2024-11-26 21:29 UTC (permalink / raw)
  To: meta

Short-lived subs are somewhat wasteful and using regexps to
suppress error messages generated by our own code is nasty.

Eric Wong (2):
  import: allow $noisy toggle, simplify `lei rediff'
  lei: avoid repeatedly recreating anonymous subs

 lib/PublicInbox/Import.pm    | 5 +++--
 lib/PublicInbox/LEI.pm       | 4 +++-
 lib/PublicInbox/LeiRediff.pm | 7 ++-----
 3 files changed, 8 insertions(+), 8 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] import: allow $noisy toggle, simplify `lei rediff'
  2024-11-26 21:29 [PATCH 0/2] lei: short-lived sub reductions Eric Wong
@ 2024-11-26 21:29 ` Eric Wong
  2024-11-26 21:29 ` [PATCH 2/2] lei: avoid repeatedly recreating anonymous subs Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2024-11-26 21:29 UTC (permalink / raw)
  To: meta

Creating an anonymous sub for $SIG{__WARN__} every time
`lei rediff' is called is wasteful.  Instead, provide a
knob to prevent the unnecessary warning from being emitted
by PublicInbox::Import in the first place so we can use the
existing warn_ignore_cb.
---
 lib/PublicInbox/Import.pm    | 5 +++--
 lib/PublicInbox/LeiRediff.pm | 7 ++-----
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index ae46c5f4..e6d725fc 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -22,6 +22,7 @@ use autodie qw(socketpair);
 use Carp qw(croak);
 use Socket qw(AF_UNIX SOCK_STREAM);
 use PublicInbox::IO qw(read_all);
+our $noisy = 1;
 
 sub default_branch () {
 	state $default_branch = do {
@@ -297,7 +298,7 @@ sub extract_cmt_info ($;$) {
 		utf8::encode($email);
 	} else {
 		$email = '';
-		warn "no email in From: $from or Sender: $sender\n";
+		warn "no email in From: $from or Sender: $sender\n" if $noisy;
 	}
 
 	# git gets confused with:
@@ -309,7 +310,7 @@ sub extract_cmt_info ($;$) {
 		utf8::encode($name);
 	} else {
 		$name = '';
-		warn "no name in From: $from or Sender: $sender\n";
+		warn "no name in From: $from or Sender: $sender\n" if $noisy;
 	}
 
 	my $subject = delete($smsg->{Subject}) // '(no subject)';
diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm
index 59fee3f6..6df2a96b 100644
--- a/lib/PublicInbox/LeiRediff.pm
+++ b/lib/PublicInbox/LeiRediff.pm
@@ -223,11 +223,8 @@ sub dequote_add { # Eml each_part callback
 sub input_eml_cb { # callback for all emails
 	my ($self, $eml) = @_;
 	{
-		local $SIG{__WARN__} = sub {
-			return if "@_" =~ /^no email in From: .*? or Sender:/;
-			return if PublicInbox::Eml::warn_ignore(@_);
-			warn @_;
-		};
+		local $PublicInbox::Import::noisy;
+		local $SIG{__WARN__} = \&PublicInbox::Eml::warn_ignore_cb;
 		$self->{tmp_sto}->add_eml($eml);
 		$eml->each_part(\&dequote_add, $self) if $self->{dqre};
 		$self->{tmp_sto}->done;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] lei: avoid repeatedly recreating anonymous subs
  2024-11-26 21:29 [PATCH 0/2] lei: short-lived sub reductions Eric Wong
  2024-11-26 21:29 ` [PATCH 1/2] import: allow $noisy toggle, simplify `lei rediff' Eric Wong
@ 2024-11-26 21:29 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2024-11-26 21:29 UTC (permalink / raw)
  To: meta

The SIGTERM handler doesn't change, so we can reuse it across
different instances without repeatedly creating a new one since
(AFAIK) perl(1) isn't able to deduplicate identical subs.  In
any case, looping `local $SIG{TERM} = $coderef' reveals a minor
speedup compared to the equivalent `local $SIG{TERM} = sub {...}'.
---
 lib/PublicInbox/LEI.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index fc7d190a..34ef95a1 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -590,6 +590,8 @@ sub note_sigpipe { # triggers sigpipe_handler
 	x_it($self, 13);
 }
 
+my $term_handler = sub { exit(128 + 15) };
+
 sub _lei_atfork_child {
 	my ($self, $persist) = @_;
 	# we need to explicitly close things which are on stack
@@ -629,7 +631,7 @@ sub _lei_atfork_child {
 			$cb->(@_) unless PublicInbox::Eml::warn_ignore(@_)
 		};
 	}
-	$SIG{TERM} = sub { exit(128 + 15) };
+	$SIG{TERM} = $term_handler;
 	$current_lei = $persist ? undef : $self; # for SIG{__WARN__}
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-26 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-26 21:29 [PATCH 0/2] lei: short-lived sub reductions Eric Wong
2024-11-26 21:29 ` [PATCH 1/2] import: allow $noisy toggle, simplify `lei rediff' Eric Wong
2024-11-26 21:29 ` [PATCH 2/2] lei: avoid repeatedly recreating anonymous subs Eric Wong

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