Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 3568A431FD0 for ; Fri, 21 Jan 2011 01:59:49 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wA9ER4uoxzDi for ; Fri, 21 Jan 2011 01:59:48 -0800 (PST) Received: from mail.loccal.net (gw.loccal.net [94.142.235.206]) by olra.theworths.org (Postfix) with ESMTP id A1027431FB6 for ; Fri, 21 Jan 2011 01:59:47 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.loccal.net (Postfix) with ESMTP id E57FE563D; Fri, 21 Jan 2011 11:12:22 +0100 (CET) X-Virus-Scanned: amavisd-new at loccal.net Received: from mail.loccal.net ([127.0.0.1]) by localhost (mail.loccal.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tdn0bdnivyZu; Fri, 21 Jan 2011 11:12:18 +0100 (CET) Received: from steelpick.2x.cz (unknown [10.21.129.4]) by mail.loccal.net (Postfix) with ESMTPS id CA40810456; Fri, 21 Jan 2011 11:12:18 +0100 (CET) Received: from wsh by steelpick.2x.cz with local (Exim 4.72) (envelope-from ) id 1PgDmP-0003jg-16; Fri, 21 Jan 2011 10:59:41 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH 1/3] Do not defer maildir flag synchronization during the first notmuch new Date: Fri, 21 Jan 2011 10:59:34 +0100 Message-Id: <1295603977-14326-2-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1295603977-14326-1-git-send-email-sojkam1@fel.cvut.cz> References: <1295603977-14326-1-git-send-email-sojkam1@fel.cvut.cz> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jan 2011 09:59:49 -0000 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