* [PATCH 5/8] nntp: cmd_listgroup: use named subs 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 listgroup_range_i and listgroup_all_i subs which
do the same things as the anonymous subs they replace.
---
lib/PublicInbox/NNTP.pm | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index dff1bcd2..c288d06b 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -190,6 +190,22 @@ sub cmd_list ($;$$) {
'.'
}
+sub listgroup_range_i {
+ my ($self, $beg, $end) = @_;
+ my $r = $self->{ng}->mm->msg_range($beg, $end, 'num');
+ scalar(@$r) or return;
+ more($self, join("\r\n", map { $_->[0] } @$r));
+ 1;
+}
+
+sub listgroup_all_i {
+ my ($self, $num) = @_;
+ my $ary = $self->{ng}->mm->ids_after($num);
+ scalar(@$ary) or return;
+ more($self, join("\r\n", @$ary));
+ 1;
+}
+
sub cmd_listgroup ($;$$) {
my ($self, $group, $range) = @_;
if (defined $group) {
@@ -197,26 +213,13 @@ sub cmd_listgroup ($;$$) {
return $res if ($res !~ /\A211 /);
more($self, $res);
}
- my $ng = $self->{ng} or return '412 no newsgroup selected';
- my $mm = $ng->mm;
+ $self->{ng} or return '412 no newsgroup selected';
if (defined $range) {
my $r = get_range($self, $range);
return $r unless ref $r;
- my ($beg, $end) = @$r;
- long_response($self, sub {
- $r = $mm->msg_range($beg, $end, 'num');
- scalar(@$r) or return;
- more($self, join("\r\n", map { $_->[0] } @$r));
- 1;
- });
+ long_response($self, \&listgroup_range_i, @$r);
} else { # grab every article number
- my $n = 0;
- long_response($self, sub {
- my $ary = $mm->ids_after(\$n);
- scalar(@$ary) or return;
- more($self, join("\r\n", @$ary));
- 1;
- });
+ long_response($self, \&listgroup_all_i, \(my $num = 0));
}
}
^ 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 5/8] nntp: cmd_listgroup: use named subs 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 5/8] nntp: cmd_listgroup: use named subs 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).