]> git.notmuchmail.org Git - notmuch/commit
Make keys of notmuch-tag-formats regexps and use caching
authorAustin Clements <amdragon@MIT.EDU>
Sat, 22 Mar 2014 11:51:06 +0000 (11:51 +0000)
committerDavid Bremner <david@tethera.net>
Mon, 24 Mar 2014 22:43:00 +0000 (19:43 -0300)
commit7023466ece21b43a62dc0a2502e84bea78b1501c
treee83eeed749e3694bdd2712a9dbe3a1c258b98c75
parentdfab8e5e49d90c415f9585a02a2b0d6f72b4083a
Make keys of notmuch-tag-formats regexps and use caching

This modifies `notmuch-tag-format-tag' to treat the keys of
`notmuch-tag-formats' as (anchored) regexps, rather than literal
strings.  This is clearly more flexible, as it allows for prefix
matching, defining a fallback format, etc.  This may cause compatibility
problems if people have customized `notmuch-tag-formats' to match tags
that contain regexp specials, but this seems unlikely.

Regular expression matching has quite a performance hit over string
lookup, so this also introduces a simple cache from exact tags to
formatted strings.  The number of unique tags is likely to be quite
small, so this cache should have a high hit rate.  In addition to
eliminating the regexp lookup in the common case, this cache stores
fully formatted tags, eliminating the repeated evaluation of potentially
expensive, user-specified formatting code.  This makes regexp lookup at
least as fast as assoc for unformatted tags (e.g., inbox) and *faster*
than the current code for formatted tags (e.g., unread):

                    inbox (usec)   unread (usec)
    assoc:              0.4            2.8
    regexp:             3.2            7.2
    regexp+caching:     0.4            0.4

(Though even at 7.2 usec, tag formatting is not our top bottleneck.)

This cache must be explicitly cleared to keep it coherent, so this adds
the appropriate clearing calls.
emacs/notmuch-show.el
emacs/notmuch-tag.el
emacs/notmuch-tree.el
emacs/notmuch.el