Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: bdwalton@gmail.com (Ben Walton)
Subject: [sup-talk] [PATCH] maildir speedups
Date: Thu, 29 May 2008 09:34:09 -0400	[thread overview]
Message-ID: <f96e0240805290634x7575c75fsd7d147491d42e6ad@mail.gmail.com> (raw)
In-Reply-To: <1212028646-sup-7356@spooky.local>

On Wed, May 28, 2008 at 10:49 PM, Grant Hollingworth <grant at antiflux.org> 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| !@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?

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 <bdwalton at gmail.com>

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

---------------------------------------------------------------------------------------------------------------------------


  parent reply	other threads:[~2008-05-29 13:34 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
2008-05-29  3:05           ` Grant Hollingworth
2008-05-29  3:06             ` Grant Hollingworth
2008-05-29 13:34           ` Ben Walton [this message]
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=f96e0240805290634x7575c75fsd7d147491d42e6ad@mail.gmail.com \
    --to=bdwalton@gmail.com \
    /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