about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-01 10:14:28 +0000
committerEric Wong <e@80x24.org>2016-05-01 10:14:28 +0000
commitc3756b2ef7af9a2f0385f1069c228ccea334ada6 (patch)
treeaca7a574e96a30e20c78cf136064be80ceea69ed /lib/PublicInbox/HTTP.pm
parent2a3554b1acd18d3b2904147ce0893cfec02d83a6 (diff)
downloadpublic-inbox-c3756b2ef7af9a2f0385f1069c228ccea334ada6.tar.gz
We can reduce the allocation and overhead needed for
Danga::Socket timers for immediately-executed responses by
combining identical timers and reducing anonymous sub creation.
Diffstat (limited to 'lib/PublicInbox/HTTP.pm')
-rw-r--r--lib/PublicInbox/HTTP.pm12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 414fc733..88b6fb81 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -223,6 +223,15 @@ sub more ($$) {
         $self->write($_[1]);
 }
 
+my $pipelineq = [];
+my $next_tick;
+sub process_pipelineq () {
+        $next_tick = undef;
+        my $q = $pipelineq;
+        $pipelineq = [];
+        rbuf_process($_) foreach @$q;
+}
+
 # overrides existing Danga::Socket method
 sub event_write {
         my ($self) = @_;
@@ -232,7 +241,8 @@ sub event_write {
         if ($self->{rbuf} eq '') { # wait for next request
                 $self->watch_read(1);
         } else { # avoid recursion for pipelined requests
-                Danga::Socket->AddTimer(0, sub { rbuf_process($self) });
+                push @$pipelineq, $self;
+                $next_tick ||= Danga::Socket->AddTimer(0, *process_pipelineq);
         }
 }