about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 13:51:33 +0000
committerEric Wong <e@80x24.org>2021-01-01 05:00:39 +0000
commitf7ce917c8dfba330586791ceb4bdd06bc61c0547 (patch)
tree726f964509d30795466db6ead7c5937a2939cda2 /lib
parent3ae5275eb187ed00bb83061a4d37a161bc8eb3e7 (diff)
downloadpublic-inbox-f7ce917c8dfba330586791ceb4bdd06bc61c0547.tar.gz
Some testing will be needed to see if it's worth the code
and maintenance overhead, but it seems easy-enough to get
working.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/IPC.pm29
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm
index c04140ae..0baa218c 100644
--- a/lib/PublicInbox/IPC.pm
+++ b/lib/PublicInbox/IPC.pm
@@ -9,6 +9,29 @@ use v5.10.1;
 use Socket qw(AF_UNIX SOCK_STREAM);
 use Carp qw(confess croak);
 use PublicInbox::Sigfd;
+my ($enc, $dec);
+# ->imports at BEGIN turns serial_*_with_object into custom ops on 5.14+
+# and eliminate method call overhead
+BEGIN {
+        eval {
+                require Sereal::Encoder;
+                require Sereal::Decoder;
+                Sereal::Encoder->import('sereal_encode_with_object');
+                Sereal::Decoder->import('sereal_decode_with_object');
+                ($enc, $dec) = (Sereal::Encoder->new, Sereal::Decoder->new);
+        };
+};
+
+if ($enc && $dec) { # should be custom ops
+        *freeze = sub ($) { sereal_encode_with_object $enc, $_[0] };
+        *thaw = sub ($) { sereal_decode_with_object $dec, $_[0], my $ret };
+} else {
+        eval { # some distros have Storable as a separate package from Perl
+                require Storable;
+                Storable->import(qw(freeze thaw));
+                $enc = 1;
+        } // warn("Storable (part of Perl) missing: $@\n");
+}
 
 sub _get_rec ($) {
         my ($sock) = @_;
@@ -52,11 +75,7 @@ sub ipc_worker_loop ($$) {
 
 sub ipc_worker_spawn ($$$) {
         my ($self, $ident, $oldset) = @_;
-        eval { require Storable; Storable->import(qw(freeze thaw)); };
-        if ($@) {
-                state $w //= warn "Storable (part of Perl) missing: $@\n";
-                return;
-        }
+        return unless $enc;
         my $pid = $self->{-ipc_worker_pid};
         confess "BUG: already spawned PID:$pid" if $pid;
         confess "BUG: already have worker socket" if $self->{-ipc_sock};