From: Eric Wong Date: Tue, 26 Nov 2024 21:29:23 +0000 (+0000) Subject: lei: avoid repeatedly recreating anonymous subs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13852defff9046463d809eff1fce18efc58fb098;p=thirdparty%2Fpublic-inbox.git 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 {...}'. --- 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__} }