From mboxrd@z Thu Jan 1 00:00:00 1970 From: grant@antiflux.org (Grant Hollingworth) Date: Wed, 28 May 2008 22:49:32 -0400 Subject: [sup-talk] [PATCH] maildir speedups In-Reply-To: <1211682829-sup-9284@south> References: <1211254100-sup-9575@south> <1211682829-sup-9284@south> Message-ID: <1212028646-sup-7356@spooky.local> * 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| !@ids.include?(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?