* [PATCH 7/8] nntp: hdr_msg_id: use named sub for long_response
2019-12-21 7:59 7% [PATCH 0/8] nntp: eliminate response-duration cyclic refs Eric Wong
@ 2019-12-21 8:00 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-12-21 8:00 UTC (permalink / raw)
To: meta
Introduce hdr_msgid_range_i, which does the same thing as the
anonymous sub it replaces.
---
lib/PublicInbox/NNTP.pm | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index ec9ac287..b2927b79 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -656,6 +656,14 @@ sub long_response ($$;@) {
undef;
}
+sub hdr_msgid_range_i {
+ my ($self, $beg, $end) = @_;
+ my $r = $self->{ng}->mm->msg_range($beg, $end);
+ @$r or return;
+ more($self, join("\r\n", map { "$_->[0] <$_->[1]>" } @$r));
+ 1;
+}
+
sub hdr_message_id ($$$) { # optimize XHDR Message-ID [range] for slrnpull.
my ($self, $xhdr, $range) = @_;
@@ -667,17 +675,8 @@ sub hdr_message_id ($$$) { # optimize XHDR Message-ID [range] for slrnpull.
$range = $self->{article} unless defined $range;
my $r = get_range($self, $range);
return $r unless ref $r;
- my $mm = $self->{ng}->mm;
- my ($beg, $end) = @$r;
more($self, $xhdr ? r221 : r225);
- long_response($self, sub {
- my $r = $mm->msg_range($beg, $end);
- @$r or return;
- more($self, join("\r\n", map {
- "$_->[0] <$_->[1]>"
- } @$r));
- 1;
- });
+ long_response($self, \&hdr_msgid_range_i, @$r);
}
}
^ permalink raw reply related [relevance 6%]
* [PATCH 0/8] nntp: eliminate response-duration cyclic refs
@ 2019-12-21 7:59 7% Eric Wong
2019-12-21 8:00 6% ` [PATCH 7/8] nntp: hdr_msg_id: use named sub for long_response Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-12-21 7:59 UTC (permalink / raw)
To: meta
While there are no known memory leaks in our code, the short-lived
reference cycle introduced by the long_response API is a potential
source of bugs.
Change the long_response API and update callers to pass
parameter explicitly to named subroutines instead of anonymous
ones.
Since creating new anonymous subs (aka "closures") take a fair
amount of memory in Perl, this ought to reduce memory pressure,
as well, since we're now only creating lightweight references to
long-lived subs. The tradeoff is we make a few more hash
lookups since we no longer cache some hash lookups into local
variables onto the stack.
Eric Wong (8):
nntp: get_range: return scalarref for $beg
nntp: remove cyclic refs from long_response
nntp: hdr_searchmsg: use named sub for numeric range response
nntp: cmd_xrover: use named sub for long_response
nntp: cmd_listgroup: use named subs for long_response
nntp: cmd_newnews: use named sub for long_response
nntp: hdr_msg_id: use named sub for long_response
nntp: cmd_xover: use named sub for long_response
lib/PublicInbox/NNTP.pm | 293 +++++++++++++++++++++-------------------
1 file changed, 152 insertions(+), 141 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-12-21 7:59 7% [PATCH 0/8] nntp: eliminate response-duration cyclic refs Eric Wong
2019-12-21 8:00 6% ` [PATCH 7/8] nntp: hdr_msg_id: use named sub for long_response Eric Wong
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).