From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 86E051F522 for ; Mon, 26 Sep 2022 10:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1664187436; bh=eL1gZZuyY7J/uZ1AwD4MMupZ13/shV0kKcbnzOlYgQc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KBnNtfzEc0HXw0yXBExEGUYrf7X2tWUwI3s78RCqv7ebcRxJ7/wcIpRo5pY2d9zcn L7yOg3yEFGRZHD6Wj5jFaWpEBdg8wXsDSg4j0Bwlso4/mAmOke9DRCXG3dy6JoEfKH oflvmiApjA7twpEtG9LawV3eBc+BzVC9FshcFQuk= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/4] viewvcs: load blobs asynchronously Date: Mon, 26 Sep 2022 10:17:14 +0000 Message-Id: <20220926101715.1853-4-e@80x24.org> In-Reply-To: <20220926101715.1853-1-e@80x24.org> References: <20220926101715.1853-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This actually leads to a nice 3-5% speedup under parallel loads when using git(1) w/o SHA-1 collision detection enabled. Gcf2 is slower since libgit2 has SHA-1 collision detection enabled on my system. Since we're in the area, improve location of comments w.r.t. cgit CSS class names and note the reliance on scratchpad for performance in a tight loop. --- lib/PublicInbox/ViewVCS.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index f740591d..915cf2c5 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -413,11 +413,21 @@ sub solve_result { blob $oid $size bytes $raw_link EOM } + @{$ctx->{-paths}} = ($path, $raw_link); + $ctx->{git} = $git; + if ($ctx->{env}->{'pi-httpd.async'}) { + ibx_async_cat($ctx, $oid, \&show_blob, $ctx); + } else { # synchronous + $git->cat_async($oid, \&show_blob, $ctx); + $git->cat_async_wait; + } +} - my $blob = $git->cat_file($oid); - if (!$blob) { # WTF? +sub show_blob { # git->cat_async callback + my ($blob, $oid, $type, $size, $ctx) = @_; + if (!$blob) { my $e = "Failed to retrieve generated blob ($oid)"; - warn "$e ($git->{git_dir})"; + warn "$e ($ctx->{git}->{git_dir}) type=$type"; return html_page($ctx, 500, "
$e
".dbg_log($ctx)) } @@ -428,6 +438,7 @@ EOM return delete($ctx->{-wcb})->([200, $h, [ $$blob ]]); } + my ($path, $raw_link) = @{delete $ctx->{-paths}}; $bin and return html_page($ctx, 200, "
blob $oid $size bytes (binary)" .
 				" $raw_link
".dbg_log($ctx)); @@ -445,14 +456,14 @@ EOM $$blob = ascii_html($$blob); } + # using some of the same CSS class names and ids as cgit my $x = "
blob $oid $size bytes $raw_link
" . "
". "
";
+	# scratchpad in this loop is faster here than `printf $zfh':
 	$x .= sprintf("% ${pad}u\n", $_) for (1..$nl);
 	$x .= '
 
'. # pad for non-CSS users ""; - - # using some of the same CSS class names and ids as cgit html_page($ctx, 200, $x, $ctx->{-linkify}->linkify_2($$blob), ''.dbg_log($ctx)); }