about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-14 02:56:36 +0000
committerEric Wong <e@80x24.org>2019-07-14 02:57:15 +0000
commitd327141cee62b2efec2c859a237023d7ff9e71a5 (patch)
treed68457bf1559279d5fa54727675a82a4d8c776f6
parent4b82e287358c9cd858456798c7f09881d2d274aa (diff)
downloadpublic-inbox-d327141cee62b2efec2c859a237023d7ff9e71a5.tar.gz
We don't need to keep an empty buffer around in the common case
when a client is sending us completely inflatable requests and
we're able to read them in one go.

This only seems to save about 2M with 10K NNTPS clients using
COMPRESS, so it's not a huge win, but better than nothing.
-rw-r--r--lib/PublicInbox/NNTPdeflate.pm13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/PublicInbox/NNTPdeflate.pm b/lib/PublicInbox/NNTPdeflate.pm
index f2de0f38..c143488f 100644
--- a/lib/PublicInbox/NNTPdeflate.pm
+++ b/lib/PublicInbox/NNTPdeflate.pm
@@ -56,7 +56,7 @@ sub enable {
         unlock_hash(%$self);
         $self->res('206 Compression active');
         bless $self, $class;
-        $self->{zin} = [ $in, '' ];
+        $self->{zin} = $in;
 }
 
 # overrides PublicInbox::NNTP::compressed
@@ -67,13 +67,16 @@ sub do_read ($$$$) {
         my ($self, $rbuf, $len, $off) = @_;
 
         my $zin = $self->{zin} or return; # closed
-        my $deflated = \($zin->[1]);
-        my $r = PublicInbox::DS::do_read($self, $deflated, $len) or return;
+        my $doff;
+        my $dbuf = delete($self->{dbuf}) // '';
+        $doff = length($dbuf);
+        my $r = PublicInbox::DS::do_read($self, \$dbuf, $len, $doff) or return;
 
         # assert(length($$rbuf) == $off) as far as NNTP.pm is concerned
-        # -ConsumeInput is true, so $deflated is automatically emptied
-        my $err = $zin->[0]->inflate($deflated, $rbuf);
+        # -ConsumeInput is true, so $dbuf is automatically emptied
+        my $err = $zin->inflate($dbuf, $rbuf);
         if ($err == Z_OK) {
+                $self->{dbuf} = $dbuf if $dbuf ne '';
                 $r = length($$rbuf) and return $r;
                 # nothing ready, yet, get more, later
                 $self->requeue;