From eeeae20893a2595631359e719eadac9686572734 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2020 07:04:22 +0000 Subject: imap: use git-cat-file asynchronously This ought to improve overall performance with multiple clients. Single client performance suffers a tiny bit due to extra syscall overhead from epoll. This also makes the existing async interface easier-to-use, since calling cat_async_begin is no longer required. --- lib/PublicInbox/Git.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 54c163e8..c5a3fa46 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -156,7 +156,7 @@ sub my_readline ($$) { } } -sub _cat_async_step ($$) { +sub cat_async_step ($$) { my ($self, $inflight) = @_; die 'BUG: inflight empty or odd' if scalar(@$inflight) < 2; my ($cb, $arg) = splice(@$inflight, 0, 2); @@ -178,7 +178,7 @@ sub cat_async_wait ($) { my ($self) = @_; my $inflight = delete $self->{inflight} or return; while (scalar(@$inflight)) { - _cat_async_step($self, $inflight); + cat_async_step($self, $inflight); } } @@ -277,6 +277,7 @@ sub qx { # returns true if there are pending "git cat-file" processes sub cleanup { my ($self) = @_; + cat_async_wait($self); _destroy($self, qw(--batch in out pid)); _destroy($self, qw(--batch-check in_c out_c pid_c err_c)); !!($self->{pid} || $self->{pid_c}); @@ -334,9 +335,9 @@ sub cat_async_begin { sub cat_async ($$$;$) { my ($self, $oid, $cb, $arg) = @_; - my $inflight = $self->{inflight} or die 'BUG: not in async'; + my $inflight = $self->{inflight} // cat_async_begin($self); if (scalar(@$inflight) >= MAX_INFLIGHT) { - _cat_async_step($self, $inflight); + cat_async_step($self, $inflight); } print { $self->{out} } $oid, "\n" or fail($self, "write error: $!"); @@ -358,7 +359,6 @@ sub modified ($) { my ($self) = @_; my $modified = 0; my $fh = popen($self, qw(rev-parse --branches)); - cat_async_begin($self); local $/ = "\n"; while (my $oid = <$fh>) { chomp $oid; -- cgit v1.2.3-24-ge0c7