From 195c40c82e77c73e171f75529b80c7561565d512 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Jan 2020 06:28:16 +0000 Subject: www: discard multipart parent on iteration We're often iterating through messages while writing to another buffer in our WWW interface, causing memory usage to multiply. Since we know we won't need to keep the MIME object around in some cases, and can tell msg_iter to clobber the on-stack variable while it operates on subparts of multipart messages. With xt/mem-msgview.t switched to multipart from the previous commit, this shows a 13 MB memory reduction on that test. --- lib/PublicInbox/MsgIter.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/MsgIter.pm') diff --git a/lib/PublicInbox/MsgIter.pm b/lib/PublicInbox/MsgIter.pm index cdd78b39..f238954b 100644 --- a/lib/PublicInbox/MsgIter.pm +++ b/lib/PublicInbox/MsgIter.pm @@ -12,10 +12,11 @@ use PublicInbox::MIME; # Like Email::MIME::walk_parts, but this is: # * non-recursive # * passes depth and indices to the iterator callback -sub msg_iter ($$;$) { - my ($mime, $cb, $cb_arg) = @_; +sub msg_iter ($$;$$) { + my ($mime, $cb, $cb_arg, $do_undef) = @_; my @parts = $mime->subparts; if (@parts) { + $mime = $_[0] = undef if $do_undef; # saves some memory my $i = 0; @parts = map { [ $_, 1, ++$i ] } @parts; while (my $p = shift @parts) { -- cgit v1.2.3-24-ge0c7