]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: save memory by dropping smsg->{from_name} on use
authorEric Wong <e@80x24.org>
Sat, 9 Oct 2021 12:03:36 +0000 (12:03 +0000)
committerEric Wong <e@80x24.org>
Sat, 9 Oct 2021 21:31:08 +0000 (21:31 +0000)
We'll also save a few LoC when generating it.  $smsg objects can
linger a while when rendering large threads, so saving a few
bytes here can add up to several hundred KB saved.

I noticed this while chasing the ref cycle leak in commit
b28e74c9dc0a (www: fix ref cycle from threading w/ extindex, 2021-10-03).
While there's no longer a leak, releasing memory earlier can
allow it to be reused sooner and reduce both memory traffic and
memory pressure.

lib/PublicInbox/SearchView.pm
lib/PublicInbox/Smsg.pm
lib/PublicInbox/View.pm

index 91196ccafc9f21a710b6fe71bafadc18f190315c..e74ddb9056c81412877f4d40be4e748bbdba9603 100644 (file)
@@ -122,7 +122,7 @@ sub mset_summary {
                $min = $pct;
 
                my $s = ascii_html($smsg->{subject});
-               my $f = ascii_html($smsg->{from_name});
+               my $f = ascii_html(delete $smsg->{from_name});
                if ($obfs_ibx) {
                        obfuscate_addrs($obfs_ibx, $s);
                        obfuscate_addrs($obfs_ibx, $f);
index fb28eff7326e06d19e05cc1a096fc55cf54b3bdd..a2f54507425f546785754770ba49fa87cb26417d 100644 (file)
@@ -57,15 +57,12 @@ sub load_from_data ($$) {
 sub psgi_cull ($) {
        my ($self) = @_;
 
-       # ghosts don't have ->{from}
-       my $from = delete($self->{from}) // '';
-       my @n = PublicInbox::Address::names($from);
-       $self->{from_name} = join(', ', @n);
-
        # drop NNTP-only fields which aren't relevant to PSGI results:
        # saves ~80K on a 200 item search result:
        # TODO: we may need to keep some of these for JMAP...
-       delete @$self{qw(tid to cc bytes lines)};
+       my ($f) = delete @$self{qw(from tid to cc bytes lines)};
+       # ghosts don't have ->{from}
+       $self->{from_name} = join(', ', PublicInbox::Address::names($f // ''));
        $self;
 }
 
index a6944b80bbed08ca41c702c234b1010571b1e5ac..116aa6418c4404475913b740f8ad373924077b8c 100644 (file)
@@ -978,7 +978,7 @@ sub skel_dump { # walk_thread callback
                $$skel .= delete($ctx->{sl_note}) || '';
        }
 
-       my $f = ascii_html($smsg->{from_name});
+       my $f = ascii_html(delete $smsg->{from_name});
        my $obfs_ibx = $ctx->{-obfs_ibx};
        obfuscate_addrs($obfs_ibx, $f) if $obfs_ibx;