[RFC PATCH 2/5] cli: drop inode sort order on directories unknown to the database

Jani Nikula jani at nikula.org
Fri Apr 15 12:29:16 PDT 2016


The claim is that inode sort order leads to faster filesystem
operation:

commit a45ff8c36112a2f17c1ad5c20a16c30a47759797
Author: Stewart Smith <stewart at flamingspork.com>
Date:   Wed Nov 18 12:56:40 2009 +1100

    Read mail directory in inode number order

The numbers cited seem convincing, but since then we've limited the
inode sorting to directories new to the database. Directories known to
the database are scanned in asciibetical order.

Making this change helps future work, and having it as a standalone
step makes it easier to evaluate the potential performance impact.
---
 notmuch-new.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 2d975eb5b640..930cbbc9b86f 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -151,12 +151,6 @@ generic_print_progress (const char *action, const char *object,
 }
 
 static int
-dirent_sort_inode (const struct dirent **a, const struct dirent **b)
-{
-    return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
-}
-
-static int
 dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
 {
     return strcmp ((*a)->d_name, (*b)->d_name);
@@ -415,11 +409,10 @@ add_files (notmuch_database_t *notmuch,
     }
 
     /* If the database knows about this directory, then we sort based
-     * on strcmp to match the database sorting. Otherwise, we can do
-     * inode-based sorting for faster filesystem operation. */
+     * on strcmp to match the database sorting. */
     num_fs_entries = scandir (path, &fs_entries, 0,
 			      directory ?
-			      dirent_sort_strcmp_name : dirent_sort_inode);
+			      dirent_sort_strcmp_name : NULL);
 
     if (num_fs_entries == -1) {
 	fprintf (stderr, "Error opening directory %s: %s\n",
@@ -722,7 +715,7 @@ count_files (const char *path, int *count, add_files_state_t *state)
     struct dirent *entry = NULL;
     char *next;
     struct dirent **fs_entries = NULL;
-    int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
+    int num_fs_entries = scandir (path, &fs_entries, 0, NULL);
     int entry_type, i;
 
     if (num_fs_entries == -1) {
-- 
2.1.4



More information about the notmuch mailing list