Hi,

while playing around with large binary mails I found that a simple
change to the queue/* plugins can speed up queueing quite a bit. With
the default $transaction->body_getline loop it takes ~0.5 seconds (on
my test system) to queue an 18MB Mail to a maildir. With a simple diff
it drops down to ~0.1 seconds.

Any objections against modifying all queue/* plugins like this? Or
better provide a $transaction->body_getblock($size) which falls back to
return one line if the mail is not spooled to disk?

Index: plugins/queue/maildir
===================================================================
--- plugins/queue/maildir       (revision 769)
+++ plugins/queue/maildir       (working copy)
@@ -61,9 +61,17 @@
 
   $transaction->header->print(\*MF);
   $transaction->body_resetpos;
-  while (my $line = $transaction->body_getline) {
-    print MF $line;
+  my $fh = $transaction->body_fh;
+  if (!$fh) { # not spooled to disk
+    while (my $line = $transaction->body_getline) {
+      print MF $line;
+    }
   }
+  else {
+    while (my $size = $fh->read(my $line, 4096)) {
+      print MF $line;
+    }
+  }
 
   close MF or
     $self->log(LOGWARN, "could not close $maildir/tmp/$file: $!")

Reply via email to