From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 37C5B1FB0F for ; Sat, 9 Oct 2021 12:03:37 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/4] view: save memory by dropping smsg->{from_name} on use Date: Sat, 9 Oct 2021 12:03:36 +0000 Message-Id: <20211009120336.2057-5-e@80x24.org> In-Reply-To: <20211009120336.2057-1-e@80x24.org> References: <20211009120336.2057-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 2 +- lib/PublicInbox/Smsg.pm | 9 +++------ lib/PublicInbox/View.pm | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 91196cca..e74ddb90 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -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); diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm index fb28eff7..a2f54507 100644 --- a/lib/PublicInbox/Smsg.pm +++ b/lib/PublicInbox/Smsg.pm @@ -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; } diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index a6944b80..116aa641 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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;