diff options
author | Eric Wong <e@yhbt.net> | 2020-03-19 03:32:53 -0500 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-03-20 18:22:51 +0000 |
commit | 8fb8fc52420ef669c5b9c583d32647e9fbdffd88 (patch) | |
tree | fd72fc5be02fd3e5bb901f2330626756534a5d89 /lib | |
parent | c713cd419189cbe5cf72b6e60e846458985ffcdb (diff) | |
download | public-inbox-8fb8fc52420ef669c5b9c583d32647e9fbdffd88.tar.gz |
We already lazy-load WwwListing for the CGI script, and hiding another layer of lazy-loading makes things difficult to do WWW->preload. We want long-lived processes to do all long-lived allocations up front to avoid fragmentation in the allocator, but we'll still support short-lived processes by lazy-loading individual modules in the PublicInbox::* namespace. Mixing up allocation lifetimes (e.g. doing immortal allocations while a large amount of space is taken by short-lived objects) will cause fragmentation in any allocator which favors large contiguous regions for performance reasons. This includes any malloc implementation which relies on sbrk() for the primary heap, including glibc malloc.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/WwwListing.pm | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index a8aecaf7..33cb0ace 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -10,11 +10,19 @@ use PublicInbox::Hval qw(ascii_html prurl); use PublicInbox::Linkify; use PublicInbox::View; use PublicInbox::Inbox; -use bytes (); +use bytes (); # bytes::length use HTTP::Date qw(time2str); use Digest::SHA (); use File::Spec (); *try_cat = \&PublicInbox::Inbox::try_cat; +our $json; +if (eval { require IO::Compress::Gzip }) { + for my $mod (qw(JSON::MaybeXS JSON JSON::PP)) { + eval "require $mod" or next; + # ->ascii encodes non-ASCII to "\uXXXX" + $json = $mod->new->ascii(1); + } +} sub list_all_i { my ($ibx, $arg) = @_; @@ -121,16 +129,6 @@ sub html ($$) { [ $code, $h, [ $out ] ]; } -my $json; -sub _json () { - for my $mod (qw(JSON::MaybeXS JSON JSON::PP)) { - eval "require $mod" or next; - # ->ascii encodes non-ASCII to "\uXXXX" - return $mod->new->ascii(1); - } - die; -} - sub fingerprint ($) { my ($git) = @_; # TODO: convert to qspawn for fairness when there's @@ -201,7 +199,8 @@ sub manifest_add ($$;$$) { # manifest.js.gz sub js ($$) { my ($env, $list) = @_; - eval { require IO::Compress::Gzip } or return [ 404, [], [] ]; + # $json won't be defined if IO::Compress::Gzip is missing + $json or return [ 404, [], [] ]; my $manifest = { -abs2urlpath => {}, -mtime => 0 }; for my $ibx (@$list) { @@ -221,8 +220,7 @@ sub js ($$) { $repo->{reference} = $abs2urlpath->{$abs}; } my $out; - IO::Compress::Gzip::gzip(\(($json ||= _json())->encode($manifest)) => - \$out); + IO::Compress::Gzip::gzip(\($json->encode($manifest)) => \$out); $manifest = undef; [ 200, [ qw(Content-Type application/gzip), 'Last-Modified', time2str($mtime), |