]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidxshard: reduce syscalls when writing ->eidx_key
authorEric Wong <e@80x24.org>
Sat, 7 Nov 2020 10:56:53 +0000 (10:56 +0000)
committerEric Wong <e@80x24.org>
Sun, 8 Nov 2020 10:18:16 +0000 (10:18 +0000)
We use ->autoflush(1) on this pipe to ensure the shard workers
see data immediately on print; so this means we have to do our
own buffering for optional data.

lib/PublicInbox/SearchIdxShard.pm

index e194b7e0aa1f0ab2e3e464e6fbc163ea36655824..9566d23461bb71e67e967742e375133c51cd5cbf 100644 (file)
@@ -114,14 +114,11 @@ sub shard_worker_loop ($$$$$) {
 sub index_raw {
        my ($self, $msgref, $eml, $smsg, $ibx) = @_;
        if (my $w = $self->{w}) {
-               if ($ibx) {
-                       print $w 'X=', $ibx->eidx_key, "\0" or die
-                               "failed to write shard: $!\n";
-               }
+               my @ekey = $ibx ? ('X='.$ibx->eidx_key."\0") : ();
                $msgref //= \($eml->as_string);
                $smsg->{raw_bytes} //= length($$msgref);
                # mid must be last, it can contain spaces (but not LF)
-               print $w join(' ', @$smsg{qw(raw_bytes bytes
+               print $w @ekey, join(' ', @$smsg{qw(raw_bytes bytes
                                                num blob ds ts tid mid)}),
                        "\n", $$msgref or die "failed to write shard $!\n";
        } else {