]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: avoid repeatedly recreating anonymous subs
authorEric Wong <e@80x24.org>
Tue, 26 Nov 2024 21:29:23 +0000 (21:29 +0000)
committerEric Wong <e@80x24.org>
Wed, 27 Nov 2024 20:34:59 +0000 (20:34 +0000)
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

index fc7d190a48264066f658c6c800229360e3a0c6e3..34ef95a150898e56a77f42f6c2957469d875bb85 100644 (file)
@@ -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__}
 }