From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2E6731F518 for ; Thu, 29 Aug 2024 23:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1724973965; bh=4ychAAb40w0NeyvhJknkF7EG4uarJ8M9HvRp+t9fp8Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=3bDSVQrTNQ+x1yqIkXuZ+no9EjdbXD+s6CLnWYU5CQscTuqZ3WMYfXQBMEWyqC9Pk QzagSl4g2qzAuKZHX8W8aVo/Zl0x7K5M62vB92QUpwOHq0Zg+E40aQ8Jrr52vZrvUn Bb9I8WOlSpS6kxRKJClFWekvcKMIr2T8eGQm6P8U= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/3] solver: use async_check for the temporary git repo Date: Thu, 29 Aug 2024 23:26:03 +0000 Message-ID: <20240829232603.2120168-4-e@80x24.org> In-Reply-To: <20240829232603.2120168-1-e@80x24.org> References: <20240829232603.2120168-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While the temporary git repo is likely in cache and not subject to high seek latency as normal code repos are, inflating objects still takes a non-trivial amount of time. So use this as an opportunity to serve other clients and exploit parallelism in SMP systems. --- lib/PublicInbox/SolverGit.pm | 49 ++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index 6dd222a9..d50a2fd1 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -385,21 +385,28 @@ EOF sub do_finish ($) { my ($self) = @_; - my ($found, $oid_want) = @$self{qw(found oid_want)}; - if (my $exists = $found->{$oid_want}) { + my $oid_want = $self->{oid_want}; + if (my $exists = $self->{found}->{$oid_want}) { return done($self, $exists); } # let git disambiguate if oid_want was too short, # but long enough to be unambiguous: - my $tmp_git = $self->{tmp_git}; - if (my @res = $tmp_git->check($oid_want)) { - return done($self, $found->{$res[0]}); - } - if (my $err = $tmp_git->last_check_err) { - dbg($self, $err); + if ($self->{psgi_env}->{'pi-httpd.async'}) { + async_check { git => $self->{tmp_git} }, $oid_want, + \&finish_cb, $self + } else { + my ($hex, $type) = $self->{tmp_git}->check($oid_want); + finish_cb(undef, $hex, $type // 'missing', undef, $self) } - done($self, undef); +} + +sub finish_cb { # async_check cb + my (undef, $oid_full, $type, undef, $self) = @_; + return done $self, $self->{found}->{$oid_full} if $type eq 'blob'; + my $err = $self->{tmp_git}->last_check_err; + dbg $self, $err if $err; + done $self, undef; } sub event_step ($) { @@ -456,9 +463,10 @@ sub mark_found ($$$) { sub parse_ls_files ($$) { my ($self, $bref) = @_; - my ($qsp_err, $di) = delete @$self{qw(-qsp_err -cur_di)}; + my $qsp_err = delete $self->{-qsp_err}; die "git ls-files -s -z error:$qsp_err" if $qsp_err; + my $di = $self->{-cur_di}; my @ls = split(/\0/, $$bref); my ($line, @extra) = grep(/\t\Q$di->{path_b}\E\z/, @ls); scalar(@extra) and die "BUG: extra files in index: <", @@ -469,14 +477,23 @@ sub parse_ls_files ($$) { $file eq $di->{path_b} or die "BUG: index mismatch: file=$file != path_b=$di->{path_b}"; + dbg($self, "index at:\n$mode_b $oid_b_full\t$file"); my $tmp_git = $self->{tmp_git} or die 'no git working tree'; - my (undef, undef, $size) = $tmp_git->check($oid_b_full); - defined($size) or die "check $oid_b_full failed"; + if ($self->{psgi_env}->{'pi-httpd.async'}) { + async_check { git => $tmp_git }, $oid_b_full, + \&ck_size_cb, $self + } else { + ck_size_cb(undef, $tmp_git->check($oid_b_full), $self); + } +} - dbg($self, "index at:\n$mode_b $oid_b_full\t$file"); - my $created = [ $tmp_git, $oid_b_full, 'blob', $size, $di ]; - mark_found($self, $di->{oid_b}, $created); - next_step($self); # onto the next patch +sub ck_size_cb { # async_check cb + my (undef, $oid_b_full, undef, $size, $self) = @_; + $size // die "check $oid_b_full failed"; + my $di = delete $self->{-cur_di} // die 'BUG: no -cur_di'; + my $created = [ $self->{tmp_git}, $oid_b_full, 'blob', $size, $di ]; + mark_found $self, $di->{oid_b}, $created; + next_step $self; # onto the next patch } sub ls_files_result {