unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Michal Sojka <sojkam1@fel.cvut.cz>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/3] new: Do not defer maildir flag synchronization during the first run
Date: Fri, 21 Jan 2011 10:59:35 +0100	[thread overview]
Message-ID: <1295603977-14326-3-git-send-email-sojkam1@fel.cvut.cz> (raw)
In-Reply-To: <1295603977-14326-1-git-send-email-sojkam1@fel.cvut.cz>

When notmuch new is run for the first time, it is not necessary to defer
maildir flags synchronization to later because we already know that no
files will be removed.

Performing the maildinr flag synchronization immediately after the
message is added to the database has the advantage that the message is
likely hot in the disk cache so the synchronization is faster.
Additionally, we also save one database query for each message, which
must be performed when the operation is deferred.

Without this patchi, the first notmuch new of 200k messages (3 GB) took
1h and 46m out of which 20m was maildir flags synchronization. With this
patch, the whole operation took only 1h and 36m.
---
 notmuch-new.c |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index cdf8513..a2af045 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -420,19 +420,35 @@ add_files_recursive (notmuch_database_t *notmuch,
 	    state->added_messages++;
 	    for (tag=state->new_tags; *tag != NULL; tag++)
 	        notmuch_message_add_tag (message, *tag);
-	    /* Defer sync of maildir flags until after old filenames
-	     * are removed in the case of a rename. */
-	    if (state->synchronize_flags == TRUE)
-		_filename_list_add (state->message_ids_to_sync,
-				    notmuch_message_get_message_id (message));
+	    if (state->synchronize_flags == TRUE) {
+		if (!state->total_files) {
+		    /* Defer sync of maildir flags until after old filenames
+		     * are removed in the case of a rename. */
+		    _filename_list_add (state->message_ids_to_sync,
+					notmuch_message_get_message_id (message));
+		} else {
+		    /* During the first notmuch new we synchronize
+		     * flags immediately, while the message is hot in
+		     * disk cache. */
+		    notmuch_message_maildir_flags_to_tags (message);
+		}
+	    }
 	    break;
 	/* Non-fatal issues (go on to next file) */
 	case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-	    /* Defer sync of maildir flags until after old filenames
-	     * are removed in the case of a rename. */
-	    if (state->synchronize_flags == TRUE)
-		_filename_list_add (state->message_ids_to_sync,
-				    notmuch_message_get_message_id (message));
+	    if (state->synchronize_flags == TRUE) {
+		if (!state->total_files) {
+		    /* Defer sync of maildir flags until after old filenames
+		     * are removed in the case of a rename. */
+		    _filename_list_add (state->message_ids_to_sync,
+					notmuch_message_get_message_id (message));
+		} else {
+		    /* During the first notmuch new we synchronize
+		     * flags immediately, while the message is hot in
+		     * disk cache. */
+		    notmuch_message_maildir_flags_to_tags (message);
+		}
+	    }
 	    break;
 	case NOTMUCH_STATUS_FILE_NOT_EMAIL:
 	    fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
-- 
1.7.2.3

  parent reply	other threads:[~2011-01-21  9:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21  9:59 [PATCH 0/3] Speedups and enhancements of notmuch new Michal Sojka
2011-01-21  9:59 ` [PATCH 1/3] Do not defer maildir flag synchronization during the first " Michal Sojka
2011-01-21  9:59 ` Michal Sojka [this message]
2011-01-25 22:42   ` [PATCH 1/3] new: Do not defer maildir flag synchronization during the first run Austin Clements
2011-01-26  9:15     ` Carl Worth
2011-01-26 11:59       ` Carl Worth
2011-01-26 15:07         ` Austin Clements
2011-01-26 16:50           ` Michal Sojka
2011-01-27  5:04           ` Carl Worth
2011-01-27  5:43             ` Austin Clements
2011-01-30  0:21               ` Rob Browning
2011-01-21  9:59 ` [PATCH 2/3] new: Add all initial tags at once Michal Sojka
2011-01-26 12:10   ` Carl Worth
2011-01-26 16:52   ` Thomas Schwinge
2011-01-27  5:03     ` Carl Worth
2011-01-27  7:14       ` Carl Worth
2011-01-27 11:08         ` Michal Sojka
2011-01-21  9:59 ` [PATCH 3/3] new: Enhance progress reporting Michal Sojka
2011-01-26 12:23   ` Carl Worth
2011-01-26 13:16     ` Michal Sojka
2011-01-26 13:06   ` [PATCH] new: Print progress estimates only when we have sufficient information Michal Sojka
2011-01-26 13:49     ` Carl Worth
  -- strict thread matches above, loose matches on Subject: below --
2011-01-28  0:08 [PATCH 1/3] new: Do not defer maildir flag synchronization during the first run Austin Clements
2011-01-28  8:51 ` Sebastian Spaeth

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

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295603977-14326-3-git-send-email-sojkam1@fel.cvut.cz \
    --to=sojkam1@fel.cvut.cz \
    --cc=notmuch@notmuchmail.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).