unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/5] nntp: small speed up for multi-line responses
Date: Fri,  4 Dec 2020 22:03:46 +0000	[thread overview]
Message-ID: <20201204220349.4408-3-e@80x24.org> (raw)
In-Reply-To: <20201204220349.4408-1-e@80x24.org>

Using a non-zero-length separator for `join' requires extra work
inside Perl.  We can shove the cost of appending "\r\n" into the
`map' loop, instead.  This speeds up the `join' operation.

The "deferred" log entry for a "LISTGROUP org.kernel.vger.linux-kernel"
command (with nearly 3.8 million messages) goes from ~3.96s to 3.86s
on my workstation.
---
 lib/PublicInbox/NNTP.pm | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 6728f9c5..05d2d13b 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -204,7 +204,7 @@ 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));
+	$self->msg_more(join('', map { "$_->[0]\r\n" } @$r));
 	1;
 }
 
@@ -327,10 +327,9 @@ sub newnews_i {
 		if (my $over = $ibx->over) {
 			my $msgs = $over->query_ts($ts, $$prev);
 			if (scalar @$msgs) {
-				more($self, '<' .
-					join(">\r\n<",
-						map { $_->{mid} } @$msgs ) .
-					'>');
+				$self->msg_more(join('', map {
+							"<$_->{mid}>\r\n";
+						} @$msgs));
 				$$prev = $msgs->[-1]->{num};
 				return 1; # continue on current group
 			}
@@ -707,7 +706,7 @@ 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));
+	$self->msg_more(join('', map { "$_->[0] <$_->[1]>\r\n" } @$r));
 	1;
 }
 
@@ -774,8 +773,8 @@ sub xref_range_i {
 	my $msgs = $ng->over->query_xover($$beg, $end);
 	scalar(@$msgs) or return;
 	$$beg = $msgs->[-1]->{num} + 1;
-	more($self, join("\r\n", map {
-		"$_->{num} ".xref($self, $ng, $_);
+	$self->msg_more(join('', map {
+		"$_->{num} ".xref($self, $ng, $_) . "\r\n";
 	} @$msgs));
 	1;
 }
@@ -934,7 +933,7 @@ sub over_line ($$$) {
 		$smsg->{lines},
 		"Xref: " . xref($self, $ng, $smsg));
 	utf8::encode($s);
-	$s
+	$s .= "\r\n";
 }
 
 sub cmd_over ($;$) {
@@ -953,7 +952,7 @@ sub cmd_over ($;$) {
 			$smsg->{-orig_num} = $smsg->{num};
 			$smsg->{num} = 0;
 		}
-		more($self, over_line($self, $ng, $smsg));
+		$self->msg_more(over_line($self, $ng, $smsg));
 		'.';
 	} else {
 		cmd_xover($self, $range);
@@ -967,7 +966,7 @@ sub xover_i {
 	my $nr = scalar @$msgs or return;
 
 	# OVERVIEW.FMT
-	more($self, join("\r\n", map {
+	$self->msg_more(join('', map {
 		over_line($self, $ng, $_);
 		} @$msgs));
 	$$beg = $msgs->[-1]->{num} + 1;

  parent reply	other threads:[~2020-12-04 22:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 22:03 [PATCH 0/5] more ->ALL usage Eric Wong
2020-12-04 22:03 ` [PATCH 1/5] nntp: xref_by_tc: simplify slightly Eric Wong
2020-12-04 22:03 ` Eric Wong [this message]
2020-12-04 22:03 ` [PATCH 3/5] search: remove mdocid export Eric Wong
2020-12-04 22:03 ` [PATCH 4/5] newswww: use ->ALL to avoid O(n) inbox scan Eric Wong
2020-12-04 22:03 ` [PATCH 5/5] extmsg: use ->ALL for "global" MID lookups Eric Wong

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=20201204220349.4408-3-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.
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).