Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: grant@antiflux.org (Grant Hollingworth)
Subject: [sup-talk] [PATCH] maildir speedups
Date: Wed, 28 May 2008 22:49:32 -0400	[thread overview]
Message-ID: <1212028646-sup-7356@spooky.local> (raw)
In-Reply-To: <1211682829-sup-9284@south>

* 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?


  reply	other threads:[~2008-05-29  2:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-30 18:50 Ben Walton
2008-05-20  3:29 ` William Morgan
     [not found]   ` <f96e0240805200924u1c991392oe36de853e208bab8@mail.gmail.com>
2008-05-21  1:08     ` Ben Walton
2008-05-25  2:34       ` William Morgan
2008-05-29  2:49         ` Grant Hollingworth [this message]
2008-05-29  3:05           ` Grant Hollingworth
2008-05-29  3:06             ` Grant Hollingworth
2008-05-29 13:34           ` Ben Walton
2008-05-30 16:26             ` William Morgan
2008-06-04  0:39               ` Ben Walton
2008-06-04  2:49                 ` William Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1212028646-sup-7356@spooky.local \
    --to=grant@antiflux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox