Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] Message#text_to_chunks performance
@ 2010-10-28 12:05 Tero Tilus
  2010-11-04 16:05 ` Rich Lane
  2010-12-21 21:45 ` Tero Tilus
  0 siblings, 2 replies; 5+ messages in thread
From: Tero Tilus @ 2010-10-28 12:05 UTC (permalink / raw)
  To: Sup developers

Hi,

I ran into an issue with bad behavior of Message#text_to_chunks on
long sequences of blank lines.  Apparently I have and receive quite a
few mails with batshit crazy amounts of blank lines (the worst case
sofar being almost 200 kB worth of linefeeds ... don't ask) in them
and I want to be able to deal with them without needing to leave the
poll running overnight.

I have a naïve fix pushed to my sup fork at github (and gitorius too).

http://github.com/terotil/sup/tree/fix-text_to_chunks-performance

Is the patch-to-mailinglist still the preferred flow of contribution
as stated in Wiki?  http://sup.rubyforge.org/wiki/wiki.pl?Contributing

Do you, Rich and William, take in (properly prepared) commits from
github/gitorius forks?

--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Message#text_to_chunks performance
  2010-10-28 12:05 [sup-devel] Message#text_to_chunks performance Tero Tilus
@ 2010-11-04 16:05 ` Rich Lane
  2010-12-21 21:45 ` Tero Tilus
  1 sibling, 0 replies; 5+ messages in thread
From: Rich Lane @ 2010-11-04 16:05 UTC (permalink / raw)
  To: Tero Tilus; +Cc: Sup developers

Excerpts from Tero Tilus's message of Thu Oct 28 08:05:33 -0400 2010:
> Is the patch-to-mailinglist still the preferred flow of contribution
> as stated in Wiki?  http://sup.rubyforge.org/wiki/wiki.pl?Contributing

Yes, please send patches to the list.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Message#text_to_chunks performance
  2010-10-28 12:05 [sup-devel] Message#text_to_chunks performance Tero Tilus
  2010-11-04 16:05 ` Rich Lane
@ 2010-12-21 21:45 ` Tero Tilus
  2010-12-23 18:38   ` Rich Lane
  1 sibling, 1 reply; 5+ messages in thread
From: Tero Tilus @ 2010-12-21 21:45 UTC (permalink / raw)
  To: Sup developers

[-- Attachment #1: Type: text/plain, Size: 89 bytes --]

And here's (finally) the patch.

--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0001-Message-text_to_chunks-avoid-O-n-2-behavior-on-seq.patch --]
[-- Type: application/octet-stream, Size: 1266 bytes --]

From c496e68930f9c0e134f37c060508d52cafd06bcc Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Thu, 28 Oct 2010 14:01:12 +0300
Subject: [PATCH] Message#text_to_chunks: avoid O(n^2) behavior on sequences of blank lines

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 lib/sup/message.rb |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index cf0e505..41e6486 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -590,9 +590,20 @@ private
     state = :text # one of :text, :quote, or :sig
     chunks = []
     chunk_lines = []
+    nextline_index = -1
 
     lines.each_with_index do |line, i|
-      nextline = lines[(i + 1) ... lines.length].find { |l| l !~ /^\s*$/ } # skip blank lines
+      if i >= nextline_index
+        # look for next nonblank line only when needed to avoid O(n²)
+        # behavior on sequences of blank lines
+        if nextline_index = lines[(i+1)..-1].index { |l| l !~ /^\s*$/ } # skip blank lines
+          nextline_index += i + 1
+          nextline = lines[nextline_index]
+        else
+          nextline_index = lines.length
+          nextline = nil
+        end
+      end
 
       case state
       when :text
-- 
1.5.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Message#text_to_chunks performance
  2010-12-21 21:45 ` Tero Tilus
@ 2010-12-23 18:38   ` Rich Lane
  2011-01-19  3:12     ` Rich Lane
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Lane @ 2010-12-23 18:38 UTC (permalink / raw)
  To: Tero Tilus; +Cc: Sup developers

Branch blank-lines-perf, merged to next. I'll merge it to master after
0.12 is released.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Message#text_to_chunks performance
  2010-12-23 18:38   ` Rich Lane
@ 2011-01-19  3:12     ` Rich Lane
  0 siblings, 0 replies; 5+ messages in thread
From: Rich Lane @ 2011-01-19  3:12 UTC (permalink / raw)
  To: Tero Tilus, Sup developers

Excerpts from Rich Lane's message of Thu Dec 23 13:38:24 -0500 2010:
> Branch blank-lines-perf, merged to next. I'll merge it to master after
> 0.12 is released.

Branch blank-lines-perf has been merged to master.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-19  3:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 12:05 [sup-devel] Message#text_to_chunks performance Tero Tilus
2010-11-04 16:05 ` Rich Lane
2010-12-21 21:45 ` Tero Tilus
2010-12-23 18:38   ` Rich Lane
2011-01-19  3:12     ` Rich Lane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox