From 7c73a09c6df674e389fb20fb57f63c6bb9695d31 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 3 Jan 2021 20:58:29 +0000 Subject: lei: prefer IO::FDPass over our Inline::C recv_3fds While our recv_3fds() implementation is more efficient syscall-wise, loading Inline takes nearly 50ms on my machine even after Inline::C memoizes the build. The current ~20ms in the fast path is barely acceptable to me, and 50ms would be unusable. Eventually, script/lei may invoke tcc(1) or cc(1) directly in the fast path, but it needs @INC for the slow path, at least. We'll encode the number of FDs into the socket name allow parallel installations, for now. --- script/lei | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'script') diff --git a/script/lei b/script/lei index 029881f8..2ea98da4 100755 --- a/script/lei +++ b/script/lei @@ -4,11 +4,17 @@ use strict; use v5.10.1; use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un); -my $send_3fds; +my ($send_3fds, $nfd); if (my ($sock, $pwd) = eval { - require PublicInbox::Spawn; - $send_3fds = PublicInbox::Spawn->can('send_3fds') or die - "Inline::C not installed/configured or IO::FDPass missing\n"; + $send_3fds = eval { + require IO::FDPass; + $nfd = 1; # 1 FD per-sendmsg + sub { IO::FDPass::send($_[0], $_[$_]) for (1..3) } + } // do { + require PublicInbox::Spawn; # takes ~50ms even if built *sigh* + $nfd = 3; # 3 FDs per-sendmsg(2) + PublicInbox::Spawn->can('send_3fds'); + } // die "IO::FDPass missing or Inline::C not installed/configured\n"; my $path = do { my $runtime_dir = ($ENV{XDG_RUNTIME_DIR} // '') . '/lei'; if ($runtime_dir eq '/lei') { @@ -19,7 +25,7 @@ if (my ($sock, $pwd) = eval { require File::Path; File::Path::mkpath($runtime_dir, 0, 0700); } - "$runtime_dir/sock"; + "$runtime_dir/$nfd.sock"; }; my $addr = pack_sockaddr_un($path); socket(my $sock, AF_UNIX, SOCK_STREAM, 0) or die "socket: $!"; @@ -27,7 +33,7 @@ if (my ($sock, $pwd) = eval { local $ENV{PERL5LIB} = join(':', @INC); open(my $daemon, '-|', $^X, qw[-MPublicInbox::LEI -E PublicInbox::LEI::lazy_start(@ARGV)], - $path, $! + 0) or die "popen: $!"; + $path, $! + 0, $nfd) or die "popen: $!"; while (<$daemon>) { warn $_ } # EOF when STDERR is redirected close($daemon) or warn <<""; lei-daemon could not start, exited with \$?=$? -- cgit v1.2.3-24-ge0c7