diff options
author | Eric Wong <e@yhbt.net> | 2020-01-11 06:28:16 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-01-12 21:26:42 +0000 |
commit | 195c40c82e77c73e171f75529b80c7561565d512 (patch) | |
tree | 738c85840311d34629ae46bbc3ceb4cd9e5d8095 /lib/PublicInbox/MsgIter.pm | |
parent | 80e819ceebf922ecda684cc8ef0848ddc709a73c (diff) | |
download | public-inbox-195c40c82e77c73e171f75529b80c7561565d512.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox/MsgIter.pm')
-rw-r--r-- | lib/PublicInbox/MsgIter.pm | 5 |
1 files changed, 3 insertions, 2 deletions
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) { |