From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20211009120336.2057-5-e@80x24.org> (raw)
In-Reply-To: <20211009120336.2057-1-e@80x24.org>
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;
prev parent reply other threads:[~2021-10-09 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-09 12:03 [PATCH 0/4] WWW-related memory savings Eric Wong
2021-10-09 12:03 ` [PATCH 1/4] solver_git: shorten scalar lifetimes Eric Wong
2021-10-09 12:03 ` [PATCH 2/4] view: discard Eml->{bdy} when done using Eric Wong
2021-10-09 12:03 ` [PATCH 3/4] http: avoid Perl target cache for psgi.input Eric Wong
2021-10-09 12:03 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211009120336.2057-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).