* [PATCH 0/8] nntp: eliminate response-duration cyclic refs
@ 2019-12-21 7:59 7% Eric Wong
2019-12-21 8:00 7% ` [PATCH 3/8] nntp: hdr_searchmsg: use named sub for numeric range 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%]
* [PATCH 3/8] nntp: hdr_searchmsg: use named sub for numeric range response
2019-12-21 7:59 7% [PATCH 0/8] nntp: eliminate response-duration cyclic refs Eric Wong
@ 2019-12-21 8:00 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-12-21 8:00 UTC (permalink / raw)
To: meta
Introduce searchmsg_range_i, which does the same thing as
the anonymous sub it replaces.
---
lib/PublicInbox/NNTP.pm | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 33c557f5..30862dca 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -727,6 +727,20 @@ sub over_header_for {
$smsg->{$field};
}
+sub searchmsg_range_i {
+ my ($self, $beg, $end, $field) = @_;
+ my $over = $self->{ng}->over;
+ my $msgs = $over->query_xover($$beg, $end);
+ scalar(@$msgs) or return;
+ my $tmp = '';
+ foreach my $s (@$msgs) {
+ $tmp .= $s->{num} . ' ' . $s->$field . "\r\n";
+ }
+ utf8::encode($tmp);
+ $self->msg_more($tmp);
+ $$beg = $msgs->[-1]->{num} + 1;
+}
+
sub hdr_searchmsg ($$$$) {
my ($self, $xhdr, $field, $range) = @_;
if (defined $range && $range =~ /\A<(.+)>\z/) { # Message-ID
@@ -736,24 +750,10 @@ sub hdr_searchmsg ($$$$) {
hdr_mid_response($self, $xhdr, $ng, $n, $range, $v);
} else { # numeric range
$range = $self->{article} unless defined $range;
- my $over = $self->{ng}->over;
- my $mm = $self->{ng}->mm;
my $r = get_range($self, $range);
return $r unless ref $r;
- my ($beg, $end) = @$r;
more($self, $xhdr ? r221 : r225);
- my $cur = $$beg;
- long_response($self, sub {
- my $msgs = $over->query_xover($cur, $end);
- my $nr = scalar @$msgs or return;
- my $tmp = '';
- foreach my $s (@$msgs) {
- $tmp .= $s->{num} . ' ' . $s->$field . "\r\n";
- }
- utf8::encode($tmp);
- $self->msg_more($tmp);
- $cur = $msgs->[-1]->{num} + 1;
- });
+ long_response($self, \&searchmsg_range_i, @$r, $field);
}
}
^ permalink raw reply related [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 7% ` [PATCH 3/8] nntp: hdr_searchmsg: use named sub for numeric range 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).