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.
index_text($self, join("\n", @xnq), 1, 'XNQ');
}
index_text($self, join("\n", @xnq), 1, 'XNQ');
}
-sub index_body ($$$) {
- my ($self, $txt, $doc) = @_;
- if ($doc) {
- # does it look like a diff?
- if ($txt =~ /^(?:diff|---|\+\+\+) /ms) {
- index_diff($self, $txt, $doc);
- } else {
- index_text($self, $txt, 1, 'XNQ');
- }
- } else {
- index_text($self, $txt, 0, 'XQUOT');
- }
-}
-
sub index_xapian { # msg_iter callback
sub index_xapian { # msg_iter callback
- my ($part, $depth, @idx) = @{$_[0]};
+ my $part = $_[0]->[0]; # ignore $depth and @idx
my ($self, $doc) = @{$_[1]};
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
my ($self, $doc) = @{$_[1]};
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
my ($s, undef) = msg_part_text($part, $ct);
defined $s or return;
my ($s, undef) = msg_part_text($part, $ct);
defined $s or return;
+ $_[0]->[0] = $part = undef; # free memory
# split off quoted and unquoted blocks:
my @sections = PublicInbox::MsgIter::split_quotes($s);
# split off quoted and unquoted blocks:
my @sections = PublicInbox::MsgIter::split_quotes($s);
- $part = $s = undef;
- index_body($self, $_, /\A>/ ? 0 : $doc) for @sections;
+ undef $s; # free memory
+ for my $txt (@sections) {
+ if ($txt =~ /\A>/) {
+ index_text($self, $txt, 0, 'XQUOT');
+ } else {
+ # does it look like a diff?
+ if ($txt =~ /^(?:diff|---|\+\+\+) /ms) {
+ index_diff($self, $txt, $doc);
+ } else {
+ index_text($self, $txt, 1, 'XNQ');
+ }
+ }
+ undef $txt; # free memory
+ }
}
sub add_xapian ($$$$) {
}
sub add_xapian ($$$$) {
# split off quoted and unquoted blocks:
my @sections = PublicInbox::MsgIter::split_quotes($s);
# split off quoted and unquoted blocks:
my @sections = PublicInbox::MsgIter::split_quotes($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!
my $rv = $ctx->{obuf};
if (defined($fn) || $depth > 0 || $err) {
# badly-encoded message with $err? tell the world about it!
# regular lines, OK
$$rv .= $l->to_html($cur);
}
# regular lines, OK
$$rv .= $l->to_html($cur);
}
+ undef $cur; # free memory
}
obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};
}
obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};
my ($ctx, $cur) = @_;
my @top = split($EXTRACT_DIFFS, $$cur);
my ($ctx, $cur) = @_;
my @top = split($EXTRACT_DIFFS, $$cur);
+ undef $$cur; # free memory
my $linkify = $ctx->{-linkify};
my $dst = $ctx->{obuf};
my $linkify = $ctx->{-linkify};
my $dst = $ctx->{obuf};