From f9d88ea6c375f6f265da1a13025abcc9e38d6839 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 21 Sep 2015 11:11:09 +0000 Subject: nntp: speed up xover slightly 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(-) (limited to 'lib') diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm index 4f16762e..dd3f2912 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 d5eb4971..fb93330b 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(''); } } -- cgit v1.2.3-24-ge0c7