about summary refs log tree commit homepage
path: root/lib/PublicInbox/XapClient.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-13 13:15:40 +0000
committerEric Wong <e@80x24.org>2023-11-13 21:54:59 +0000
commitc560ab9e67476ce7b4438f8323d8ae9e775e790e (patch)
tree9ecaf00583506df226a746df54af4375cc36861e /lib/PublicInbox/XapClient.pm
parent09f486cfa17019ad742853e3158ae4a5f580180c (diff)
downloadpublic-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/XapClient.pm')
-rw-r--r--lib/PublicInbox/XapClient.pm28
1 files changed, 14 insertions, 14 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);
 }