From 13852defff9046463d809eff1fce18efc58fb098 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 26 Nov 2024 21:29:23 +0000 Subject: [PATCH] lei: avoid repeatedly recreating anonymous subs 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 fc7d190a4..34ef95a15 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__} } -- 2.47.2