]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: introduce and use Git->async_prefetch
authorEric Wong <e@yhbt.net>
Sun, 26 Jul 2020 06:57:30 +0000 (06:57 +0000)
committerEric Wong <e@yhbt.net>
Sun, 26 Jul 2020 23:46:39 +0000 (23:46 +0000)
We can keep the git process more active by sending another
request to it while fetch_run_ops() is running.  This
parallelization speeds up mutt's initial FETCH for headers by
around ~35%(!).

lib/PublicInbox/Git.pm
lib/PublicInbox/IMAP.pm

index ffc464eb32d22c11c91bbd4caabdcb883752e203..7b2ada243969fd660faca083070d78bb475ea45f 100644 (file)
@@ -410,6 +410,22 @@ sub cat_async ($$$;$) {
        push(@$inflight, $oid, $cb, $arg);
 }
 
+# this is safe to call inside $cb, but not guaranteed to enqueue
+# returns true if successful, undef if not.
+sub async_prefetch {
+       my ($self, $oid, $cb, $arg) = @_;
+       if (defined($self->{async_cat}) && (my $inflight = $self->{inflight})) {
+               # we could use MAX_INFLIGHT here w/o the halving,
+               # but lets not allow one client to monopolize a git process
+               if (scalar(@$inflight) < int(MAX_INFLIGHT/2)) {
+                       print { $self->{out} } $oid, "\n" or
+                                               fail($self, "write error: $!");
+                       return push(@$inflight, $oid, $cb, $arg);
+               }
+       }
+       undef;
+}
+
 sub extract_cmt_time {
        my ($bref, undef, undef, undef, $modified) = @_;
 
index 8ab4b1e7dba9e86853e7d93af5bc6c7627f0221e..3d66f9306ffc37c8e2664f2fb8f3acfc8c4933e4 100644 (file)
@@ -626,8 +626,13 @@ sub fetch_blob_cb { # called by git->cat_async via git_async_cat
        } else {
                $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
        }
+       my $pre;
+       if (!$self->{wbuf} && (my $nxt = $msgs->[0])) {
+               $pre = $self->{ibx}->git->async_prefetch($nxt->{blob},
+                                               \&fetch_blob_cb, $fetch_arg);
+       }
        fetch_run_ops($self, $smsg, $bref, $ops, $partial);
-       requeue_once($self);
+       $pre ? $self->zflush : requeue_once($self);
 }
 
 sub emit_rfc822 {