[PATCH 1/3] new: Do not defer maildir flag synchronization during the first run
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 21 Jan 2011 09:59:35 +0000 (10:59 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:44 +0000 (09:37 -0800)
a3/ddc65ba12705f970d71b6d4f641e38bc780674 [new file with mode: 0644]

diff --git a/a3/ddc65ba12705f970d71b6d4f641e38bc780674 b/a3/ddc65ba12705f970d71b6d4f641e38bc780674
new file mode 100644 (file)
index 0000000..bed8550
--- /dev/null
@@ -0,0 +1,125 @@
+Return-Path: <sojkam1@fel.cvut.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3F635431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 21 Jan 2011 01:59:57 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=unavailable\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id db+3GaQJ7Pxl for <notmuch@notmuchmail.org>;\r
+       Fri, 21 Jan 2011 01:59:57 -0800 (PST)\r
+Received: from mail.loccal.net (gw.loccal.net [94.142.235.206])\r
+       by olra.theworths.org (Postfix) with ESMTP id 87CFF42D280\r
+       for <notmuch@notmuchmail.org>; Fri, 21 Jan 2011 01:59:51 -0800 (PST)\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by mail.loccal.net (Postfix) with ESMTP id 6E1D210456;\r
+       Fri, 21 Jan 2011 11:12:27 +0100 (CET)\r
+X-Virus-Scanned: amavisd-new at loccal.net\r
+Received: from mail.loccal.net ([127.0.0.1])\r
+       by localhost (mail.loccal.net [127.0.0.1]) (amavisd-new, port 10024)\r
+       with LMTP id EPOwBCyJ6Cna; Fri, 21 Jan 2011 11:12:22 +0100 (CET)\r
+Received: from steelpick.2x.cz (unknown [10.21.129.4])\r
+       by mail.loccal.net (Postfix) with ESMTPS id CD8E5105B8;\r
+       Fri, 21 Jan 2011 11:12:18 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1PgDmP-0003ji-Cp; Fri, 21 Jan 2011 10:59:41 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] new: Do not defer maildir flag synchronization during the\r
+       first run\r
+Date: Fri, 21 Jan 2011 10:59:35 +0100\r
+Message-Id: <1295603977-14326-3-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1295603977-14326-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1295603977-14326-1-git-send-email-sojkam1@fel.cvut.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 21 Jan 2011 09:59:57 -0000\r
+\r
+When notmuch new is run for the first time, it is not necessary to defer\r
+maildir flags synchronization to later because we already know that no\r
+files will be removed.\r
+\r
+Performing the maildinr flag synchronization immediately after the\r
+message is added to the database has the advantage that the message is\r
+likely hot in the disk cache so the synchronization is faster.\r
+Additionally, we also save one database query for each message, which\r
+must be performed when the operation is deferred.\r
+\r
+Without this patchi, the first notmuch new of 200k messages (3 GB) took\r
+1h and 46m out of which 20m was maildir flags synchronization. With this\r
+patch, the whole operation took only 1h and 36m.\r
+---\r
+ notmuch-new.c |   36 ++++++++++++++++++++++++++----------\r
+ 1 files changed, 26 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index cdf8513..a2af045 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -420,19 +420,35 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+           state->added_messages++;\r
+           for (tag=state->new_tags; *tag != NULL; tag++)\r
+               notmuch_message_add_tag (message, *tag);\r
+-          /* Defer sync of maildir flags until after old filenames\r
+-           * are removed in the case of a rename. */\r
+-          if (state->synchronize_flags == TRUE)\r
+-              _filename_list_add (state->message_ids_to_sync,\r
+-                                  notmuch_message_get_message_id (message));\r
++          if (state->synchronize_flags == TRUE) {\r
++              if (!state->total_files) {\r
++                  /* Defer sync of maildir flags until after old filenames\r
++                   * are removed in the case of a rename. */\r
++                  _filename_list_add (state->message_ids_to_sync,\r
++                                      notmuch_message_get_message_id (message));\r
++              } else {\r
++                  /* During the first notmuch new we synchronize\r
++                   * flags immediately, while the message is hot in\r
++                   * disk cache. */\r
++                  notmuch_message_maildir_flags_to_tags (message);\r
++              }\r
++          }\r
+           break;\r
+       /* Non-fatal issues (go on to next file) */\r
+       case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+-          /* Defer sync of maildir flags until after old filenames\r
+-           * are removed in the case of a rename. */\r
+-          if (state->synchronize_flags == TRUE)\r
+-              _filename_list_add (state->message_ids_to_sync,\r
+-                                  notmuch_message_get_message_id (message));\r
++          if (state->synchronize_flags == TRUE) {\r
++              if (!state->total_files) {\r
++                  /* Defer sync of maildir flags until after old filenames\r
++                   * are removed in the case of a rename. */\r
++                  _filename_list_add (state->message_ids_to_sync,\r
++                                      notmuch_message_get_message_id (message));\r
++              } else {\r
++                  /* During the first notmuch new we synchronize\r
++                   * flags immediately, while the message is hot in\r
++                   * disk cache. */\r
++                  notmuch_message_maildir_flags_to_tags (message);\r
++              }\r
++          }\r
+           break;\r
+       case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+           fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
+-- \r
+1.7.2.3\r
+\r