unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 28/38] www: use PerlIO::scalar (zfh) for buffering
Date: Sat, 10 Sep 2022 08:17:19 +0000	[thread overview]
Message-ID: <20220910081729.2011934-29-e@80x24.org> (raw)
In-Reply-To: <20220910081729.2011934-1-e@80x24.org>

Calling Compress::Raw::Zlib::deflate is fairly expensive.
Relying on the `.=' (concat) operator inside ->zadd operator is
faster, but the method dispatch overhead is noticeable compared
to the original code where we had bare `.=' littered throughout.

Fortunately, `print' and `say' with the PerlIO::scalar IO layer
appears to offer better performance without high method dispatch
overhead.  This doesn't allow us to save as much memory as I
originally hoped, but does allow us to rely less on concat
operators in other places and just pass a list of args to
`print' and `say' as a appropriate.

This does reduce scratchpad use, however, allowing for large
memory savings, and we still ->deflate every single $eml.
---
 Documentation/mknews.perl        |  3 +-
 lib/PublicInbox/GzipFilter.pm    | 41 ++++++++++---------
 lib/PublicInbox/Mbox.pm          |  2 +-
 lib/PublicInbox/SearchView.pm    |  4 +-
 lib/PublicInbox/View.pm          | 58 +++++++++++++--------------
 lib/PublicInbox/ViewDiff.pm      | 69 ++++++++++++++++----------------
 lib/PublicInbox/WwwAtomStream.pm |  8 ++--
 lib/PublicInbox/WwwStream.pm     |  7 ++--
 8 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/Documentation/mknews.perl b/Documentation/mknews.perl
index 1936cea7..68866f44 100755
--- a/Documentation/mknews.perl
+++ b/Documentation/mknews.perl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # Generates NEWS, NEWS.atom, and NEWS.html files using release emails
 # this uses unstable internal APIs of public-inbox, and this script
@@ -46,6 +46,7 @@ if ($dst eq 'NEWS') {
 		ibx => $ibx,
 		-upfx => "$base_url/",
 		-hr => 1,
+		zfh => $out,
 	};
 	if ($dst eq 'NEWS.html') {
 		html_start($out, $ctx);
diff --git a/lib/PublicInbox/GzipFilter.pm b/lib/PublicInbox/GzipFilter.pm
index 1f11acb8..848370ce 100644
--- a/lib/PublicInbox/GzipFilter.pm
+++ b/lib/PublicInbox/GzipFilter.pm
@@ -127,38 +127,39 @@ sub write {
 	http_out($_[0])->write(translate($_[0], $_[1]));
 }
 
-sub zadd {
-	my $self = shift;
-	$self->{pbuf} .= $_ for @_; # perl internal pad memory use here
+sub zfh {
+	$_[0]->{zfh} // do {
+		open($_[0]->{zfh}, '>>', \($_[0]->{pbuf} //= '')) or
+			die "open: $!";
+		$_[0]->{zfh}
+	};
 }
 
 # similar to ->translate; use this when we're sure we know we have
 # more data to buffer after this
 sub zmore {
-	my $self = shift; # $_[1] => input
+	my $self = shift;
+	my $zfh = delete $self->{zfh};
+	if (@_ > 1 || $zfh) {
+		print { $zfh // zfh($self) } @_;
+		@_ = (delete $self->{pbuf});
+		delete $self->{zfh};
+	};
 	http_out($self);
-	my $x;
-	defined($x = delete($self->{pbuf})) and unshift(@_, $x);
-	for (@_) {
-		($x = $self->{gz}->deflate($_, $self->{zbuf})) == Z_OK or
-			die "gzip->deflate: $x";
-	}
-	undef;
+	my $err;
+	($err = $self->{gz}->deflate($_[0], $self->{zbuf})) == Z_OK or
+		die "gzip->deflate: $err";
 }
 
 # flushes and returns the final bit of gzipped data
 sub zflush ($;@) {
 	my $self = shift; # $_[1..Inf] => final input (optional)
+	zmore($self, @_) if scalar(@_) || $self->{zfh};
+	# not a bug, recursing on DS->write failure
+	my $gz = delete $self->{gz} // return '';
+	my $err;
 	my $zbuf = delete $self->{zbuf};
-	my $gz = delete $self->{gz};
-	my $x;
-	defined($x = delete($self->{pbuf})) and unshift(@_, $x);
-	for (@_) { # it's a bug iff $gz is undef if @_ isn't empty, here:
-		($x = $gz->deflate($_, $zbuf)) == Z_OK or
-			die "gzip->deflate: $x";
-	}
-	$gz // return ''; # not a bug, recursing on DS->write failure
-	($x = $gz->flush($zbuf)) == Z_OK or die "gzip->flush: $x";
+	($err = $gz->flush($zbuf)) == Z_OK or die "gzip->flush: $err";
 	$zbuf;
 }
 
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index cfe34d9c..2ef8ff2b 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -20,7 +20,7 @@ sub getline {
 	my $ibx = $ctx->{ibx};
 	my $eml = delete($ctx->{eml}) // $ibx->smsg_eml($smsg) // return;
 	my $n = $ctx->{smsg} = $ibx->over->next_by_mid(@{$ctx->{next_arg}});
-	$ctx->zadd(msg_hdr($ctx, $eml));
+	$ctx->zmore(msg_hdr($ctx, $eml));
 	if ($n) {
 		$ctx->translate(msg_body($eml));
 	} else { # last message
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index b18947ee..8932c73d 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -331,10 +331,10 @@ sub mset_thread {
 # callback for PublicInbox::WwwStream::getline
 sub mset_thread_i {
 	my ($ctx, $eml) = @_;
-	$ctx->zadd($ctx->html_top) if exists $ctx->{-html_tip};
+	print { $ctx->zfh } $ctx->html_top if exists $ctx->{-html_tip};
 	$eml and return PublicInbox::View::eml_entry($ctx, $eml);
 	my $smsg = shift @{$ctx->{msgs}} or
-		$ctx->zmore(${delete($ctx->{skel})});
+		print { $ctx->zfh } ${delete($ctx->{skel})};
 	$smsg;
 }
 
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 85dc3bd8..0753c06e 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -40,7 +40,7 @@ sub msg_page_i {
 				"../${\mid_href($smsg->{mid})}/" : '';
 		if (_msg_page_prepare($eml, $ctx)) {
 			$eml->each_part(\&add_text_body, $ctx, 1);
-			$ctx->zadd('</pre><hr>');
+			print { $ctx->{zfh} } '</pre><hr>';
 		}
 		html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg};
 		''; # XXX TODO cleanup
@@ -58,7 +58,7 @@ sub no_over_html ($) {
 	PublicInbox::WwwStream::init($ctx);
 	if (_msg_page_prepare($eml, $ctx)) { # sets {-title_html}
 		$eml->each_part(\&add_text_body, $ctx, 1);
-		$ctx->zadd('</pre><hr>');
+		print { $ctx->{zfh} } '</pre><hr>';
 	}
 	html_footer($ctx, $eml);
 	$ctx->html_done;
@@ -240,12 +240,11 @@ sub eml_entry {
 		my $html = ascii_html($irt);
 		$rv .= qq(In-Reply-To: &lt;<a\nhref="$href">$html</a>&gt;\n)
 	}
-	$rv .= "\n";
+	say { $ctx->zfh } $rv;
 
 	# scan through all parts, looking for displayable text
 	$ctx->{mhref} = $mhref;
 	$ctx->{changed_href} = "#e$id"; # for diffstat "files? changed,"
-	$ctx->zadd($rv); # XXX $rv is small, reuse below
 	$eml->each_part(\&add_text_body, $ctx, 1); # expensive
 
 	# add the footer
@@ -386,8 +385,8 @@ sub pre_thread  { # walk_thread callback
 sub thread_eml_entry {
 	my ($ctx, $eml) = @_;
 	my ($beg, $end) = thread_adj_level($ctx, $ctx->{level});
-	$ctx->zadd($beg.'<pre>');
-	eml_entry($ctx, $eml) . '</pre>' . $end;
+	print { $ctx->zfh } $beg, '<pre>';
+	print { $ctx->{zfh} } eml_entry($ctx, $eml), '</pre>', $end;
 }
 
 sub next_in_queue ($$) {
@@ -414,15 +413,15 @@ sub stream_thread_i { # PublicInbox::WwwStream::getline callback
 				if (!$ghost_ok) { # first non-ghost
 					$ctx->{-title_html} =
 						ascii_html($smsg->{subject});
-					$ctx->zadd($ctx->html_top);
+					print { $ctx->zfh } $ctx->html_top;
 				}
 				return $smsg;
 			}
 			# buffer the ghost entry and loop
-			$ctx->zadd(ghost_index_entry($ctx, $lvl, $smsg));
+			print { $ctx->zfh } ghost_index_entry($ctx, $lvl, $smsg)
 		} else { # all done
-			$ctx->zadd(join('', thread_adj_level($ctx, 0)));
-			$ctx->zadd(${delete($ctx->{skel})});
+			print { $ctx->zfh } thread_adj_level($ctx, 0),
+						${delete($ctx->{skel})};
 			return;
 		}
 	}
@@ -491,7 +490,7 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback
 		my $smsg = $ctx->{smsg};
 		if (exists $ctx->{-html_tip}) {
 			$ctx->{-title_html} = ascii_html($smsg->{subject});
-			$ctx->zadd($ctx->html_top);
+			print { $ctx->zfh } $ctx->html_top;
 		}
 		return eml_entry($ctx, $eml);
 	} else {
@@ -499,7 +498,7 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback
 			return $smsg if exists($smsg->{blob});
 		}
 		my $skel = delete($ctx->{skel}) or return; # all done
-		$ctx->zadd($$skel);
+		print { $ctx->zfh } $$skel;
 		undef;
 	}
 }
@@ -560,8 +559,9 @@ sub add_text_body { # callback for each_part
 	my $ct = $part->content_type || 'text/plain';
 	my $fn = $part->filename;
 	my ($s, $err) = msg_part_text($part, $ct);
-	$s // return $ctx->zadd(attach_link($ctx, $ct, $p, $fn) // '');
-	my $buf = $part->{is_submsg} ? submsg_hdr($ctx, $part)."\n" : '';
+	my $zfh = $ctx->zfh;
+	$s // return print $zfh (attach_link($ctx, $ct, $p, $fn) // '');
+	say $zfh submsg_hdr($ctx, $part) if $part->{is_submsg};
 
 	# makes no difference to browsers, and don't screw up filename
 	# link generation in diffs with the extra '%0D'
@@ -609,21 +609,19 @@ sub add_text_body { # callback for each_part
 	undef $s; # free memory
 	if (defined($fn) || ($depth > 0 && !$part->{is_submsg}) || $err) {
 		# badly-encoded message with $err? tell the world about it!
-		$buf .= attach_link($ctx, $ct, $p, $fn, $err) . "\n";
+		say $zfh attach_link($ctx, $ct, $p, $fn, $err);
 	}
 	delete $part->{bdy}; # save memory
-	$ctx->zadd($buf);
-	undef $buf;
 	for my $cur (@sections) { # $cur may be huge
 		if ($cur =~ /\A>/) {
 			# we use a <span> here to allow users to specify
 			# their own color for quoted text
-			$ctx->zadd(qq(<span\nclass="q">),
-					$l->to_html($cur), '</span>');
+			print $zfh qq(<span\nclass="q">),
+					$l->to_html($cur), '</span>';
 		} elsif ($diff) {
 			flush_diff($ctx, \$cur);
 		} else { # regular lines, OK
-			$ctx->zadd($l->to_html($cur));
+			print $zfh $l->to_html($cur);
 		}
 		undef $cur; # free memory
 	}
@@ -685,10 +683,10 @@ sub _msg_page_prepare {
 		$hbuf .= qq[Message-ID: &lt;$x&gt; (<a href="raw">raw</a>)\n];
 	}
 	if (!$nr) { # first (and only) message, common case
-		$ctx->zadd($ctx->html_top, $hbuf);
+		print { $ctx->zfh } $ctx->html_top, $hbuf;
 	} else {
 		delete $ctx->{-title_html};
-		$ctx->zadd($ctx->{-html_tip}, $hbuf);
+		print { $ctx->zfh } $ctx->{-html_tip}, $hbuf;
 	}
 	$ctx->{-linkify} //= PublicInbox::Linkify->new;
 	$hbuf = '';
@@ -699,7 +697,7 @@ sub _msg_page_prepare {
 			$hbuf .= "$h: $_\n" for ($eml->header_raw($h));
 		}
 		$ctx->{-linkify}->linkify_mids('..', \$hbuf, 1); # escapes HTML
-		$ctx->zadd($hbuf);
+		print { $ctx->{zfh} } $hbuf;
 		$hbuf = '';
 	}
 	my @irt = $eml->header_raw('In-Reply-To');
@@ -717,7 +715,7 @@ sub _msg_page_prepare {
 		$hbuf .= 'References: <'.join(">\n\t<", @$refs).">\n" if @$refs;
 	}
 	$ctx->{-linkify}->linkify_mids('..', \$hbuf); # escapes HTML
-	$ctx->zadd($hbuf .= "\n");
+	say { $ctx->{zfh} } $hbuf;
 	1;
 }
 
@@ -771,7 +769,7 @@ sub thread_skel ($$$) {
 sub html_footer {
 	my ($ctx, $hdr) = @_;
 	my $upfx = '../';
-	my ($related, $skel);
+	my (@related, $skel);
 	my $foot = '<pre>';
 	my $qry = delete $ctx->{-qry};
 	if ($qry && $ctx->{ibx}->isrch) {
@@ -786,7 +784,7 @@ sub html_footer {
 		$q = wrap('', '', $q);
 		my $rows = ($q =~ tr/\n/\n/) + 1;
 		$q = ascii_html($q);
-		$related = <<EOM;
+		$related[0] = <<EOM;
 <form id=related
 action=$upfx
 ><pre>find likely ancestor, descendant, or conflicting patches for <a
@@ -799,7 +797,7 @@ EOM
 	if ($ctx->{ibx}->over) {
 		my $t = ts2str($ctx->{-t_max});
 		my $t_fmt = fmt_ts($ctx->{-t_max});
-		my $fallback = $related ? "\t" : "<a id=related>\t</a>";
+		my $fallback = @related ? "\t" : "<a id=related>\t</a>";
 		$skel = <<EOF;
 ${fallback}other threads:[<a
 href="$upfx?t=$t">~$t_fmt UTC</a>|<a
@@ -834,10 +832,10 @@ EOF
 	} else { # unindexed inboxes w/o over
 		$skel = qq( <a\nhref="$upfx">latest</a>);
 	}
-	$foot .= qq(<a\nhref="#R">reply</a>);
 	# $skel may be big for big threads, don't append it to $foot
-	$skel .= '</pre>' . ($related // '');
-	$ctx->zadd($foot, $skel .= msg_reply($ctx, $hdr));
+	print { $ctx->zfh } $foot, qq(<a\nhref="#R">reply</a>),
+				$skel, '</pre>', @related,
+				msg_reply($ctx, $hdr);
 }
 
 sub ghost_parent {
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 95b615dc..5d23881b 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -67,8 +67,8 @@ sub oid ($$$) {
 }
 
 # returns true if diffstat anchor written, false otherwise
-sub anchor0 ($$$$) {
-	my ($dst, $ctx, $fn, $rest) = @_;
+sub anchor0 ($$$) {
+	my ($ctx, $fn, $rest) = @_;
 
 	my $orig = $fn;
 
@@ -84,15 +84,12 @@ sub anchor0 ($$$$) {
 	# long filenames will require us to check in anchor1()
 	push(@{$ctx->{-long_path}}, $fn) if $fn =~ s!\A\.\.\./?!!;
 
-	if (defined(my $attr = to_attr($ctx->{-apfx}.$fn))) {
-		$ctx->{-anchors}->{$attr} = 1;
-		my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
-		$$dst .= " <a\nid=i$attr\nhref=#$attr>" .
-			ascii_html($orig) . '</a>' . $spaces .
+	my $attr = to_attr($ctx->{-apfx}.$fn) // return;
+	$ctx->{-anchors}->{$attr} = 1;
+	my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
+	print { $ctx->{zfh} } " <a\nid=i$attr\nhref=#$attr>",
+			ascii_html($orig), '</a>', $spaces,
 			$ctx->{-linkify}->to_html($rest);
-		return 1;
-	}
-	undef;
 }
 
 # returns "diff --git" anchor destination, undef otherwise
@@ -156,33 +153,34 @@ sub diff_header ($$$) {
 		warn "BUG? <$$x> had no ^index line";
 	}
 	$$x =~ s!^diff --git!anchor1($ctx, $pb) // 'diff --git'!ems;
-	$ctx->zadd(qq(<span\nclass="head">$$x</span>));
+	print { $ctx->{zfh} } qq(<span\nclass="head">), $$x, '</span>';
 	$dctx;
 }
 
 sub diff_before_or_after ($$) {
 	my ($ctx, $x) = @_;
-	if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n"
+	if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n" # \$1
 			# diffstat lines:
 			((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+)
 			(\x20[0-9]+\x20files?\x20)changed,([^\n]+\n)
 			(.*?)\z/msx) { # notes, commit message, etc
 		my @x = ($5, $4, $3, $2, $1);
+		undef $$x;
 		my $lnk = $ctx->{-linkify};
-		$$x = $lnk->to_html(pop @x); # uninteresting prefix
-		for my $l (split(/^/m, pop(@x))) { # per-file diffstat lines
+		my $zfh = $ctx->{zfh};
+		print $zfh $lnk->to_html(pop @x); # $1 uninteresting prefix
+		for my $l (split(/^/m, pop(@x))) { # $2 per-file stat lines
 			$l =~ /^ (.+)( +\| .*\z)/s and
-				anchor0($x, $ctx, $1, $2) and next;
-			$$x .= $lnk->to_html($l);
+				anchor0($ctx, $1, $2) and next;
+			 print $zfh $lnk->to_html($l);
 		}
-		$$x .= pop @x; # $3 /^ \d+ files? /
 		my $ch = $ctx->{changed_href} // '#related';
-		$$x .= qq(<a href="$ch">changed</a>,);
-		$$x .= ascii_html(pop @x); # $4: insertions/deletions
-		# notes, commit message, etc
-		$ctx->zadd($$x .= $lnk->to_html(pop @x));
+		print $zfh pop(@x), # $3 /^ \d+ files? /
+			qq(<a href="$ch">changed</a>,),
+			ascii_html(pop @x), # insertions/deletions
+			$lnk->to_html(@x); # notes, commit message, etc
 	} else {
-		$ctx->zadd($ctx->{-linkify}->to_html($$x));
+		print { $ctx->{zfh} } $ctx->{-linkify}->to_html($$x);
 	}
 }
 
@@ -195,6 +193,7 @@ sub flush_diff ($$) {
 
 	my $lnk = $ctx->{-linkify};
 	my $dctx; # {}, keys: Q, oid_a, oid_b
+	my $zfh = $ctx->zfh;
 
 	while (defined(my $x = shift @top)) {
 		if (scalar(@top) >= 4 &&
@@ -202,7 +201,7 @@ sub flush_diff ($$) {
 				$top[0] =~ $IS_OID) {
 			$dctx = diff_header(\$x, $ctx, \@top);
 		} elsif ($dctx) {
-			my $after = '';
+			open(my $afh, '>>', \(my $after='')) or die "open: $!";
 
 			# Quiet "Complex regular subexpression recursion limit"
 			# warning.  Perl will truncate matches upon hitting
@@ -218,25 +217,25 @@ sub flush_diff ($$) {
 					(?:(?:^-[^\n]*\n)+)|
 					(?:^@@ [^\n]+\n))/xsm, $x)) {
 				if (!defined($dctx)) {
-					$after .= $s;
+					print $afh $s;
 				} elsif ($s =~ s/\A@@ (\S+) (\S+) @@//) {
-					$ctx->zadd(qq(<span\nclass="hunk">) .
-						diff_hunk($dctx, $1, $2) .
-						$lnk->to_html($s) .
-						'</span>');
+					print $zfh qq(<span\nclass="hunk">),
+						diff_hunk($dctx, $1, $2),
+						$lnk->to_html($s),
+						'</span>';
 				} elsif ($s =~ /\A\+/) { # $s may be huge
-					$ctx->zadd(qq(<span\nclass="add">),
+					print $zfh qq(<span\nclass="add">),
 							$lnk->to_html($s),
-							'</span>');
+							'</span>';
 				} elsif ($s =~ /\A-- $/sm) { # email sig starts
 					$dctx = undef;
-					$after .= $s;
+					print $afh $s;
 				} elsif ($s =~ /\A-/) { # $s may be huge
-					$ctx->zadd(qq(<span\nclass="del">),
-						$lnk->to_html($s),
-						'</span>');
+					print $zfh qq(<span\nclass="del">),
+							$lnk->to_html($s),
+							'</span>';
 				} else { # $s may be huge
-					$ctx->zadd($lnk->to_html($s));
+					print $zfh $lnk->to_html($s);
 				}
 			}
 			diff_before_or_after($ctx, \$after) if !$dctx;
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 1c7ae881..33da3244 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -146,15 +146,15 @@ sub feed_entry {
 	my $name = ascii_html(join(', ', PublicInbox::Address::names($from)));
 	$email = ascii_html($email // $ctx->{ibx}->{-primary_address});
 
-	$ctx->zadd(
-		(delete($ctx->{emit_header}) ? atom_header($ctx, $title) : '').
+	print { $ctx->zfh }
+		(delete($ctx->{emit_header}) ? atom_header($ctx, $title) : ''),
 		"<entry><author><name>$name</name><email>$email</email>" .
 		"</author>$title$updated" .
-		qq(<link\nhref="$href"/>).
+		qq(<link\nhref="$href"/>) .
 		"<id>$uuid</id>$irt" .
 		qq{<content\ntype="xhtml">} .
 		qq{<div\nxmlns="http://www.w3.org/1999/xhtml">} .
-		qq(<pre\nstyle="white-space:pre-wrap">));
+		qq(<pre\nstyle="white-space:pre-wrap">);
 	$ctx->{mhref} = $href;
 	$ctx->{changed_href} = "${href}#related";
 	$eml->each_part(\&PublicInbox::View::add_text_body, $ctx, 1);
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 2a318e5e..77b6f9c2 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -181,11 +181,12 @@ sub html_oneshot ($$;@) {
 		'Content-Length' => undef ];
 	bless $ctx, __PACKAGE__;
 	$ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+	my @top;
 	$ctx->{base_url} // do {
-		$ctx->zadd(html_top($ctx));
+		@top = html_top($ctx);
 		$ctx->{base_url} = base_url($ctx);
 	};
-	my $bdy = $ctx->zflush(@_[2..$#_], _html_end($ctx));
+	my $bdy = $ctx->zflush(@top, @_[2..$#_], _html_end($ctx));
 	$res_hdr->[3] = length($bdy);
 	[ $code, $res_hdr, [ $bdy ] ]
 }
@@ -216,7 +217,7 @@ sub html_init {
 	my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8'];
 	$ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env});
 	bless $ctx, __PACKAGE__;
-	$ctx->zadd(html_top($ctx));
+	print { $ctx->zfh } html_top($ctx);
 }
 
 1;

  parent reply	other threads:[~2022-09-10  8:18 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-10  8:16 [PATCH 00/38] www: reduce memory usage Eric Wong
2022-09-10  8:16 ` [PATCH 01/38] xt: fold perf-obfuscate into perf-msgview, future-proof Eric Wong
2022-09-10  8:16 ` [PATCH 02/38] www: gzip_filter: implicitly flush {obuf} on zmore/zflush Eric Wong
2022-09-10  8:16 ` [PATCH 03/38] view: rework single message page to compress earlier Eric Wong
2022-09-10  8:16 ` [PATCH 04/38] www_atom_stream: require 200 response Eric Wong
2022-09-10  8:16 ` [PATCH 05/38] www_stream: aresponse assumes 200, too Eric Wong
2022-09-10  8:16 ` [PATCH 06/38] www_text: reduce parameter passing for response header Eric Wong
2022-09-10  8:16 ` [PATCH 07/38] viewvcs: use shorter and simpler ctx->html_done Eric Wong
2022-09-10  8:16 ` [PATCH 08/38] www_listing: consolidate some ->zmore dispatches Eric Wong
2022-09-10  8:17 ` [PATCH 09/38] www_listing: avoid unnecessary work for common cases Eric Wong
2022-09-10  8:17 ` [PATCH 10/38] www: viewdiff: use return value for diff_hunk Eric Wong
2022-09-10  8:17 ` [PATCH 11/38] view: simplify _parent_headers Eric Wong
2022-09-10  8:17 ` [PATCH 12/38] view: eml_entry: reduce manipulation of ctx->{obuf} Eric Wong
2022-09-10  8:17 ` [PATCH 13/38] gzip_filter: ->translate can reuse zmore/zflush Eric Wong
2022-09-10  8:17 ` [PATCH 14/38] view: remove multipart_text_as_html Eric Wong
2022-09-10  8:17 ` [PATCH 15/38] view: reduce subroutine calls for submsg_hdr Eric Wong
2022-09-10  8:17 ` [PATCH 16/38] view: attach_link: reduce obuf manipulation Eric Wong
2022-09-10  8:17 ` [PATCH 17/38] viewdiff: reuse existing string in diff_before_or_after Eric Wong
2022-09-10  8:17 ` [PATCH 18/38] view: _th_index_lite: avoid one s///, improve symmetry Eric Wong
2022-09-10  8:17 ` [PATCH 19/38] view: _th_index_lite: use `//' defined-or op Eric Wong
2022-09-10  8:17 ` [PATCH 20/38] view: reduce ascii_html calls and {obuf} use Eric Wong
2022-09-10  8:17 ` [PATCH 21/38] view: html_footer: golf out a few lines Eric Wong
2022-09-10  8:17 ` [PATCH 22/38] view: html_footer: remove obuf dependency Eric Wong
2022-09-10  8:17 ` [PATCH 23/38] view: html_footer: avoid escaping " in a few places Eric Wong
2022-09-10  8:17 ` [PATCH 24/38] viewdiff: diff_hunk: shorten conditionals, slightly Eric Wong
2022-09-10  8:17 ` [PATCH 25/38] view: switch a few things to ctx->zmore Eric Wong
2022-09-10  8:17 ` [PATCH 26/38] www: drop {obuf} use entirely, for now Eric Wong
2022-09-10  8:17 ` [PATCH 27/38] www: switch to zadd for the majority of buffering Eric Wong
2022-09-10  8:17 ` Eric Wong [this message]
2022-09-10  8:17 ` [PATCH 29/38] viewdiff: diff_before_or_after: avoid extra capture Eric Wong
2022-09-10  8:17 ` [PATCH 30/38] viewdiff: diff_header: shorten function, slightly Eric Wong
2022-09-10  8:17 ` [PATCH 31/38] www_static: switch to `print $zfh', and optimize Eric Wong
2022-09-10  8:17 ` [PATCH 32/38] httpd/async: describe which ->write subs it can call Eric Wong
2022-09-10  8:17 ` [PATCH 33/38] translate: support multiple buffer args Eric Wong
2022-09-10  8:17 ` [PATCH 34/38] gzip_filter: write: use multi-arg translate Eric Wong
2022-09-10  8:17 ` [PATCH 35/38] feed: new_html_i: switch from zmore to `print $zfh' Eric Wong
2022-09-10  8:17 ` [PATCH 36/38] mbox*: use multi-arg ->translate and ->write Eric Wong
2022-09-10  8:17 ` [PATCH 37/38] www_listing: switch to `print $zfh' Eric Wong
2022-09-10  8:17 ` [PATCH 38/38] viewvcs: " 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=20220910081729.2011934-29-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.
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).