about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-01-05 09:51:16 +0000
committerEric Wong <e@80x24.org>2020-01-05 23:32:29 +0000
commit033f628b52ebacf4a7bf8795084ba5ec498004bf (patch)
treedf9a472915b9f1232b60921e0226d77842fc1055 /lib/PublicInbox/View.pm
parente3e8cab265fe79e4984d59ee180f2dbc8d4ef6f1 (diff)
downloadpublic-inbox-033f628b52ebacf4a7bf8795084ba5ec498004bf.tar.gz
In rare cases where Message-IDs get reused, we do not want to
hold onto the large Email::MIME objects in memory after showing
the first message.  So discard each message as soon as we're
done using it so we can save memory for the next message.

The new and expensive xt/mem-msgview.t test shows a nearly 14MB
reduction for two ~7MB messages.  run_script() also gets
upgraded to make it easier to pass large inputs via IO GLOBs.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index c38a1289..69948c4a 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -31,8 +31,8 @@ sub msg_html_i {
                 # $more cannot be true w/o $smsg being defined:
                 my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
                 $ctx->{tip} .
-                        multipart_text_as_html($ctx->{mime}, $upfx, $ctx) .
-                        '</pre><hr>'
+                        multipart_text_as_html(delete $ctx->{mime}, $upfx,
+                                                $ctx) . '</pre><hr>'
         } elsif ($more && @$more) {
                 ++$ctx->{end_nr};
                 msg_html_more($ctx, $more, $nr);
@@ -41,7 +41,7 @@ sub msg_html_i {
                 # we want to at least show the message if something
                 # here crashes:
                 eval {
-                        my $hdr = delete($ctx->{mime})->header_obj;
+                        my $hdr = delete($ctx->{hdr});
                         '<pre>' . html_footer($hdr, 1, $ctx) .
                         '</pre>' . msg_reply($ctx, $hdr)
                 };
@@ -56,7 +56,8 @@ sub msg_html {
         my ($ctx, $mime, $more, $smsg) = @_;
         my $ibx = $ctx->{-inbox};
         $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
-        $ctx->{tip} = _msg_html_prepare($mime->header_obj, $ctx, $more, 0);
+        my $hdr = $ctx->{hdr} = $mime->header_obj;
+        $ctx->{tip} = _msg_html_prepare($hdr, $ctx, $more, 0);
         $ctx->{more} = $more;
         $ctx->{end_nr} = 2;
         $ctx->{smsg} = $smsg;
@@ -95,8 +96,8 @@ sub msg_html_more {
                 my $next = $ibx->over->next_by_mid($mid, \$id, \$prev);
                 @$more = $next ? ($id, $prev, $next) : ();
                 if ($smsg) {
-                        my $mime = $smsg->{mime};
                         my $upfx = '../' . mid_escape($smsg->mid) . '/';
+                        my $mime = delete $smsg->{mime};
                         _msg_html_prepare($mime->header_obj, $ctx, $more, $nr) .
                                 multipart_text_as_html($mime, $upfx, $ctx) .
                                 '</pre><hr>'