On Wed, May 28, 2008 at 10:49 PM, Grant Hollingworth <[EMAIL PROTECTED]> wrote: > * William Morgan [2008-05-24 22:34 -0400]: >> Published on 'maildir-speedups' and merged into next. Thanks! > > Sup had my CPU working overtime after I updated. I ran ruby-prof and found > that the line > > @ids_to_fns.delete_if { |k, v| [EMAIL PROTECTED](k) } > > in Maildir#scan_mailbox was the culprit. > > Those id lists are pretty long and include? means comparing each id (a Bignum) > in @ids_to_fns with every id in @ids. > > A faster method is > > @ids_to_fns = @ids.inject({}) do |hash, i| > hash[i] = @ids_to_fns[i] > hash > end > > Or (less pretty but faster and probably clearer) > > new_ids_to_fns = {} > @ids.each {|i| new_ids_to_fns[i] = @ids_to_fns[i] } > @ids_to_fns = new_ids_to_fns > > But I guess the real question is whether the line is even needed. There > probably won't be a big difference between @ids_to_fns.keys and @ids, so why > not leave some extra values in the hash?
In hindsight, that seems rather obvious, although I've not noticed the cpu consumption on my box...Either of the above to fixes would work. I had a reason for explicitly purging old records from the mapping when I created this, but it escapes me now...dropping that line may be acceptable unless there is a reason that the keys in @ids_to_fns should be a 1:1 mapping to values in @ids. Really, there shouldn't be 'extra' keys in @ids_to_fns unless a message disappears from the Maildir anyway, which should cause an OutOfSync exception, no? Thanks -Ben -- --------------------------------------------------------------------------------------------------------------------------- Ben Walton <[EMAIL PROTECTED]> When one person suffers from a delusion, it is called insanity. When many people suffer from a delusion it is called Religion. Robert M. Pirsig, Zen and the Art of Motorcycle Maintenance --------------------------------------------------------------------------------------------------------------------------- _______________________________________________ sup-talk mailing list sup-talk@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-talk