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 3/6] nntp: speed up xover slightly
Date: Mon, 21 Sep 2015 11:11:09 +0000	[thread overview]
Message-ID: <20150921111112.18873-4-e@80x24.org> (raw)
In-Reply-To: <20150921111112.18873-1-e@80x24.org>

Reserializing the message to a string to check size wastes
considerable time and should be able to get by with slightly
less accuracy.
---
 lib/PublicInbox/GitCatFile.pm | 3 ++-
 lib/PublicInbox/NNTP.pm       | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index 4f16762..dd3f291 100644
--- a/lib/PublicInbox/GitCatFile.pm
+++ b/lib/PublicInbox/GitCatFile.pm
@@ -38,7 +38,7 @@ sub _cat_file_begin {
 }
 
 sub cat_file {
-	my ($self, $object) = @_;
+	my ($self, $object, $sizeref) = @_;
 
 	$object .= "\n";
 	my $len = bytes::length($object);
@@ -58,6 +58,7 @@ sub cat_file {
 		die "Unexpected result from git cat-file: $head\n";
 
 	my $size = $1;
+	$$sizeref = $size if $sizeref;
 	my $bytes_left = $size;
 	my $offset = 0;
 	my $rv = '';
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index d5eb497..fb93330 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -366,7 +366,8 @@ find_mid:
 	}
 found:
 	my $o = 'HEAD:' . mid2path($mid);
-	my $s = eval { Email::Simple->new($ng->gcf->cat_file($o)) };
+	my $bytes;
+	my $s = eval { Email::Simple->new($ng->gcf->cat_file($o, \$bytes)) };
 	return $err unless $s;
 	if ($set_headers) {
 		$s->header_set('Newsgroups', $ng->{name});
@@ -375,7 +376,7 @@ found:
 
 		# must be last
 		if ($set_headers == 2) {
-			$s->header_set('Bytes', bytes::length($s->as_string));
+			$s->header_set('Bytes', $bytes);
 			$s->body_set('');
 		}
 	}
-- 
EW


  parent reply	other threads:[~2015-09-21 11:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21 11:11 [PATCH 0/6] more NNTP server updates Eric Wong
2015-09-21 11:11 ` [PATCH 1/6] msgmap: minor cleanup to move constant declaration Eric Wong
2015-09-21 11:11 ` [PATCH 2/6] nntp: speed up XHDR Xref for rtin Eric Wong
2015-09-21 11:11 ` Eric Wong [this message]
2015-09-21 11:11 ` [PATCH 4/6] t/nntpd.t: improve test runnability Eric Wong
2015-09-21 11:11 ` [PATCH 5/6] remove bytes:: for length checks Eric Wong
2015-09-21 11:11 ` [PATCH 6/6] nntp: proper UTF-8 support (hopefully?) 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=20150921111112.18873-4-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).