about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-04-05 07:53:47 +0000
committerEric Wong <e@yhbt.net>2020-04-05 22:06:20 +0000
commitfec19e492eacb10f990091592f423542ab4249bd (patch)
tree075f20f90ae319b2e30e949c635fa53ff06d47f3 /lib/PublicInbox/View.pm
parentb6fc8916a05176ef006b07bba977b59cdf6a0bce (diff)
downloadpublic-inbox-fec19e492eacb10f990091592f423542ab4249bd.tar.gz
Using `undef EXPR' like a function call actually frees the heap
memory associated with the scalar, whereas `$sv = undef' or
`$sv = ""' will hold the buffer around until $sv goes out
of scope.

The `sv_set_undef' documentation in the perlapi(1) manpage
explicitly states this:

  The perl equivalent is "$sv = undef;". Note that it doesn't
  free any string buffer, unlike "undef $sv".

And I've confirmed by reading Dump() output from Devel::Peek.

We'll also inline the old index_body sub in SearchIdx.pm to make
the scope of the scalar more obvious.

This change saves several hundred kB RSS on both -index and
-httpd when hitting large emails with thousands of lines.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 1e53d8dc..ddd94e48 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -566,7 +566,7 @@ sub add_text_body { # callback for msg_iter
 
         # split off quoted and unquoted blocks:
         my @sections = PublicInbox::MsgIter::split_quotes($s);
-        $s = '';
+        undef $s; # free memory
         my $rv = $ctx->{obuf};
         if (defined($fn) || $depth > 0 || $err) {
                 # badly-encoded message with $err? tell the world about it!
@@ -587,7 +587,7 @@ sub add_text_body { # callback for msg_iter
                         # regular lines, OK
                         $$rv .= $l->to_html($cur);
                 }
-                $cur = undef;
+                undef $cur; # free memory
         }
 
         obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};