1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Optimize notmuch's performance
6 ## Use of ecryptfs slows notmuch down.
8 I noticed that my `notmuch new` was really slow (several minutes) for
9 less then 20 new emails (around 20K in my database).
11 The performance tests in the notmuch source didn't show any real
12 issue, even on a non-encrypted ext4 fs.
14 After investigation and running different tests, a switch to a
15 LUKS-btrfs based filesystem to replace the ext4-ecryptfs resolved the
16 issue. It now takes some seconds to index hundreds of messages.
18 ## Xapian 1.2.x database format: chert vs. flint
20 Xapian 1.2 (in contrast to 1.0.x) uses a new database format called
21 `chert` which is a lot faster than the old format `flint`.
23 Check whether you are on chert or flint:
25 $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
28 If it does not say `iamchert`, but `iamflint`, than you should migrate
31 There might be a file named `flintlock`, it is no indicator for your
32 database format, but also used in case of `chert`.
34 ### Migrate from flint to chert
36 Make sure you are using xapian 1.2.x (depends on your distribution)
38 XXX: add examples for different distributions
40 Backup your notmuch tags:
43 $ notmuch dump --output=notmuch-dump-b4chert
45 Move away your old database:
47 $ mv $(notmuch config get database.path)/.notmuch/ notmuch-db-b4chert
49 Find and import your messages, a new and fresh database will be
52 $ XAPIAN_PREFER_CHERT=1 notmuch new
54 I did not need the `XAPIAN_PREFER_CHERT`, but am not sure whether
55 there are situations making it necessary (certain compile-time options
56 to xapian?). This note is just here to be extended or removed by
57 somebody more knowledgeable.
59 After the initial import it is definitely not necessary to define
60 `XAPIAN_PREFER_CHERT` for subsequent calls of `notmuch new`.
64 $ notmuch restore --input=notmuch-dump-b4chert
66 Check whether you are on chert now:
68 $ ls $(notmuch config get database.path)/.notmuch/xapian/iam*
71 If it says `iamflint`, most likely you are still using xapian 1.0.x.
73 Clean-up: if you are sure everything is fine, you can delete the old
74 things. The dump of your tags you might want to keep anyway as a
75 backup - on the other hand you should have some mechanism in place to
76 make regular backups of your notmuch database:
78 $ rm notmuch-dump-b4chert
79 $ rm -R notmuch-db-b4chert
81 ### Compact your database
83 In order to greatly reduce the size of your database, you should
84 compact it. Carl says "This functionality is not yet available in the
85 Xapian library interface or else I would probably make notmuch call it
86 after building the database." and Pieter "[compacting] will cause
87 writes to be a bit more expensive in the short term, but will
88 significantly reduce the db's size, which your SSD will surely
96 $ notmuch dump --output=notmuch-dump-b4compact
100 $ cd $(notmuch config get database.path)/.notmuch
101 $ xapian-compact --no-renumber xapian xapian-compacted
103 Remove old and renamed compacted, if compacting went well:
106 $ mv xapian-compacted xapian
109 ### More information about this in the email archives:
111 * [Carl Worth](http://notmuchmail.org/pipermail/notmuch/2010/001105.html)
113 * [Sebastian Spaeth](http://notmuchmail.org/pipermail/notmuch/2011/004048.html)
115 * [Pieter Praet](http://notmuchmail.org/pipermail/notmuch/2011/004175.html)