diff options
author | Eric Wong <e@80x24.org> | 2020-01-05 09:51:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-01-05 23:32:29 +0000 |
commit | 033f628b52ebacf4a7bf8795084ba5ec498004bf (patch) | |
tree | df9a472915b9f1232b60921e0226d77842fc1055 /lib/PublicInbox/TestCommon.pm | |
parent | e3e8cab265fe79e4984d59ee180f2dbc8d4ef6f1 (diff) | |
download | public-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/TestCommon.pm')
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 68785969..d6d1e939 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -195,14 +195,20 @@ sub run_script ($;$$) { my $spawn_opt = {}; for my $fd (0..2) { my $redir = $opt->{$fd}; - next unless ref($redir); - open my $fh, '+>', undef or die "open: $!"; - $fhref->[$fd] = $fh; - $spawn_opt->{$fd} = $fh; - next if $fd > 0; - $fh->autoflush(1); - print $fh $$redir or die "print: $!"; - seek($fh, 0, SEEK_SET) or die "seek: $!"; + my $ref = ref($redir); + if ($ref eq 'SCALAR') { + open my $fh, '+>', undef or die "open: $!"; + $fhref->[$fd] = $fh; + $spawn_opt->{$fd} = $fh; + next if $fd > 0; + $fh->autoflush(1); + print $fh $$redir or die "print: $!"; + seek($fh, 0, SEEK_SET) or die "seek: $!"; + } elsif ($ref eq 'GLOB') { + $spawn_opt->{$fd} = $fhref->[$fd] = $redir; + } elsif ($ref) { + die "unable to deal with $ref $redir"; + } } if ($run_mode == 0) { # spawn an independent new process, like real-world use cases: |