diff options
author | Eric Wong <e@80x24.org> | 2022-09-10 08:17:19 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-09-10 19:50:48 +0000 |
commit | ab9c03ff4aa369b397dc1a8c8936153c8565fd05 (patch) | |
tree | 8bc61ae89d8f967ea948918d0478db291011d159 /lib/PublicInbox/WwwStream.pm | |
parent | f32456e0d0f4a7756fcc17c83ccf5b682cb512d9 (diff) | |
download | public-inbox-ab9c03ff4aa369b397dc1a8c8936153c8565fd05.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox/WwwStream.pm')
-rw-r--r-- | lib/PublicInbox/WwwStream.pm | 7 |
1 files changed, 4 insertions, 3 deletions
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; |