diff options
author | Eric Wong <e@80x24.org> | 2023-11-13 13:15:40 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-11-13 21:54:59 +0000 |
commit | c560ab9e67476ce7b4438f8323d8ae9e775e790e (patch) | |
tree | 9ecaf00583506df226a746df54af4375cc36861e /lib/PublicInbox | |
parent | 09f486cfa17019ad742853e3158ae4a5f580180c (diff) | |
download | public-inbox-c560ab9e67476ce7b4438f8323d8ae9e775e790e.tar.gz |
No need to suffer through an extra dose of slow Perl load times when we can drive the build in the big parent Perl process and get the executable path name to pass to spawn directly.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/XapClient.pm | 28 | ||||
-rw-r--r-- | lib/PublicInbox/XapHelperCxx.pm | 9 |
2 files changed, 18 insertions, 19 deletions
diff --git a/lib/PublicInbox/XapClient.pm b/lib/PublicInbox/XapClient.pm index 21c89265..dda5e044 100644 --- a/lib/PublicInbox/XapClient.pm +++ b/lib/PublicInbox/XapClient.pm @@ -11,7 +11,7 @@ use v5.12; use PublicInbox::Spawn qw(spawn); use Socket qw(AF_UNIX SOCK_SEQPACKET); use PublicInbox::IPC; -use autodie qw(pipe socketpair); +use autodie qw(fork pipe socketpair); sub mkreq { my ($self, $ios, @arg) = @_; @@ -28,19 +28,19 @@ sub mkreq { sub start_helper { my @argv = @_; socketpair(my $sock, my $in, AF_UNIX, SOCK_SEQPACKET, 0); - my $cls = ($ENV{PI_NO_CXX} ? undef : eval { - require PublicInbox::XapHelperCxx; - PublicInbox::XapHelperCxx::check_build(); - 'PublicInbox::XapHelperCxx'; - }) // do { - require PublicInbox::XapHelper; - 'PublicInbox::XapHelper'; - }; - # ensure the child process has the same @INC we do: - my $env = { PERL5LIB => join(':', @INC) }; - my $pid = spawn([$^X, ($^W ? ('-w') : ()), "-M$cls", '-e', - $cls.'::start(@ARGV)', '--', @argv], - $env, { 0 => $in }); + require PublicInbox::XapHelperCxx; + my $cls = 'PublicInbox::XapHelperCxx'; + my $env; + my $cmd = eval { PublicInbox::XapHelperCxx::cmd() }; + if ($@) { # fall back to Perl + XS|SWIG + require PublicInbox::XapHelper; + $cls = 'PublicInbox::XapHelper'; + # ensure the child process has the same @INC we do: + $env = { PERL5LIB => join(':', @INC) }; + $cmd = [$^X, ($^W ? ('-w') : ()), "-M$cls", '-e', + $cls.'::start(@ARGV)', '--' ]; + } + my $pid = spawn($cmd, $env, { 0 => $in }); ((bless { io => $sock, impl => $cls }, __PACKAGE__), $pid); } diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm index 3afdd69e..e516b111 100644 --- a/lib/PublicInbox/XapHelperCxx.pm +++ b/lib/PublicInbox/XapHelperCxx.pm @@ -114,17 +114,16 @@ sub check_build () { needs_rebuild() ? build() : 0; } -sub start (@) { +# returns spawn arg +sub cmd { check_build(); my @cmd; if (my $v = $ENV{VALGRIND}) { $v = 'valgrind -v' if $v eq '1'; @cmd = split(/\s+/, $v); } - push @cmd, $bin, @_; - my $prog = $cmd[0]; - $cmd[0] =~ s!\A.*?/([^/]+)\z!$1!; - exec { $prog } @cmd; + push @cmd, $bin; + \@cmd; } 1; |