* [PATCH 6/8] nntp: cmd_newnews: 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 5% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-12-21 8:00 UTC (permalink / raw)
To: meta
Introduce newnews_i, which does the same thing as the anonymous
sub it replaces.
---
lib/PublicInbox/NNTP.pm | 45 ++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index c288d06b..ec9ac287 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -300,6 +300,26 @@ sub ngpat2re (;$) {
$_[0] = qr/\A(?:$_[0])\z/;
}
+sub newnews_i {
+ my ($self, $overs, $ts, $prev) = @_;
+ my $over = $overs->[0];
+ my $msgs = $over->query_ts($ts, $$prev);
+ if (scalar @$msgs) {
+ more($self, '<' .
+ join(">\r\n<", map { $_->mid } @$msgs ).
+ '>');
+ $$prev = $msgs->[-1]->{num};
+ } else {
+ shift @$overs;
+ if (@$overs) { # continue onto next newsgroup
+ $$prev = 0;
+ return 1;
+ } else { # break out of the long response.
+ return;
+ }
+ }
+}
+
sub cmd_newnews ($$$$;$$) {
my ($self, $newsgroups, $date, $time, $gmt, $dists) = @_;
my $ts = eval { parse_time($date, $time, $gmt) };
@@ -308,34 +328,17 @@ sub cmd_newnews ($$$$;$$) {
my ($keep, $skip) = split('!', $newsgroups, 2);
ngpat2re($keep);
ngpat2re($skip);
- my @over;
+ my @overs;
foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{newsgroup} =~ $keep or next;
$ng->{newsgroup} =~ $skip and next;
my $over = $ng->over or next;
- push @over, $over;
+ push @overs, $over;
};
- return '.' unless @over;
+ return '.' unless @overs;
my $prev = 0;
- long_response($self, sub {
- my $over = $over[0];
- my $msgs = $over->query_ts($ts, $prev);
- if (scalar @$msgs) {
- more($self, '<' .
- join(">\r\n<", map { $_->mid } @$msgs ).
- '>');
- $prev = $msgs->[-1]->{num};
- } else {
- shift @over;
- if (@over) { # continue onto next newsgroup
- $prev = 0;
- return 1;
- } else { # break out of the long response.
- return;
- }
- }
- });
+ long_response($self, \&newnews_i, \@overs, $ts, \$prev);
}
sub cmd_group ($$) {
^ permalink raw reply related [relevance 5%]
* [PATCH 0/8] nntp: eliminate response-duration cyclic refs
@ 2019-12-21 7:59 7% Eric Wong
2019-12-21 8:00 5% ` [PATCH 6/8] nntp: cmd_newnews: 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 5% ` [PATCH 6/8] nntp: cmd_newnews: 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).