user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] viewvcs: load blobs asynchronously
Date: Mon, 26 Sep 2022 10:17:14 +0000	[thread overview]
Message-ID: <20220926101715.1853-4-e@80x24.org> (raw)
In-Reply-To: <20220926101715.1853-1-e@80x24.org>

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</pre>
 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, "<pre><b>$e</b></pre>".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,
 				"<pre>blob $oid $size bytes (binary)" .
 				" $raw_link</pre>".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 = "<pre>blob $oid $size bytes $raw_link</pre>" .
 		"<hr /><table\nclass=blob>".
 		"<tr><td\nclass=linenumbers><pre>";
+	# scratchpad in this loop is faster here than `printf $zfh':
 	$x .= sprintf("<a id=n$_ href=#n$_>% ${pad}u</a>\n", $_) for (1..$nl);
 	$x .= '</pre></td><td><pre> </pre></td>'. # pad for non-CSS users
 		"<td\nclass=lines><pre\nstyle='white-space:pre'><code>";
-
-	# using some of the same CSS class names and ids as cgit
 	html_page($ctx, 200, $x, $ctx->{-linkify}->linkify_2($$blob),
 		'</code></pre></td></tr></table>'.dbg_log($ctx));
 }

  parent reply	other threads:[~2022-09-26 10:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 10:17 [PATCH 0/4] some minor performance tweaks Eric Wong
2022-09-26 10:17 ` [PATCH 1/4] viewdiff: save memory by eliminating two captures Eric Wong
2022-09-26 10:17 ` [PATCH 2/4] gcf2: support worktree $GIT_DIR Eric Wong
2022-09-26 10:17 ` Eric Wong [this message]
2022-09-26 10:17 ` [PATCH 4/4] git: reduce early bare-bones memory use Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220926101715.1853-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).