From: Eric Wong Date: Mon, 26 Sep 2022 10:17:14 +0000 (+0000) Subject: viewvcs: load blobs asynchronously X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=4be57c1329b13dbeb8097dd49b5e43fbc9ec9754 viewvcs: load blobs asynchronously 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. --- 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)); }