[sup-talk] [PATCH] maildir speedups
Grant Hollingworth
grant at antiflux.org
Wed May 28 22:49:32 EDT 2008
* 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?
More information about the sup-talk
mailing list