--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 9F89D431FBC\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 14:08:49 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 HacakvWkBfXv for <notmuch@notmuchmail.org>;\r
+ Thu, 24 Oct 2013 14:08:43 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\r
+ by olra.theworths.org (Postfix) with ESMTP id 51C7B431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 14:08:43 -0700 (PDT)\r
+X-AuditID: 12074425-b7f1c8e0000009c7-2f-52698c5a4118\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 86.BB.02503.A5C89625; Thu, 24 Oct 2013 17:08:42 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r9OL8f3q027338; \r
+ Thu, 24 Oct 2013 17:08:41 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9OL8dFW030896\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Thu, 24 Oct 2013 17:08:41 -0400\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1VZS90-0005w3-Vb; Thu, 24 Oct 2013 17:08:39 -0400\r
+Date: Thu, 24 Oct 2013 17:08:37 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] new: Don't scan unchanged directories with no\r
+ sub-directories\r
+Message-ID: <20131024210837.GH20337@mit.edu>\r
+References: <1382646822-24556-1-git-send-email-amdragon@mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1382646822-24556-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT0Y3qyQwyaN1jZHH95kxmi47bu9kc\r
+ mDyerbrF7PHx6S2WAKYoLpuU1JzMstQifbsEroxHXSuYCx4KV0zb9JqtgbGXv4uRk0NCwETi\r
+ 8vzr7BC2mMSFe+vZuhi5OIQE9jFKLF3wAMrZyCixa+MvKOc0k8Sm43+YQVqEBJYwSrzqkQax\r
+ WQRUJZonfwIbxSagIbFt/3JGEFtEQFpi593ZrF2MHBzMArISr38pgISFBUIk9m86CVbCK6Aj\r
+ cWDaaiaIkQ4S/X+vsEPEBSVOznzCAmIzC2hJ3Pj3kglijLTE8n8cIGFOAUeJJ0fXg5WICqhI\r
+ TDm5jW0Co9AsJN2zkHTPQuhewMi8ilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdCLzezRC81pXQT\r
+ IzioXVR3ME44pHSIUYCDUYmHt+FTepAQa2JZcWXuIUZJDiYlUd6E9swgIb6k/JTKjMTijPii\r
+ 0pzU4kOMEhzMSiK80/SAcrwpiZVVqUX5MClpDhYlcd5bHPZBQgLpiSWp2ampBalFMFkZDg4l\r
+ CV6hbqBGwaLU9NSKtMycEoQ0EwcnyHAeoOGPukCGFxck5hZnpkPkTzEqSonz6oI0C4AkMkrz\r
+ 4HphSecVozjQK8K8hSBVPMCEBdf9CmgwE9DgKUvSQAaXJCKkpBoYrRsX7Mgvnvc2V8fXcf+8\r
+ U5LiSiYLPn4UrQ9OurpZ6LLLqojij7IXEzf4ef46mLLyoQ/zi3v/WtfIrK/REqvzlfPQjPVc\r
+ 6DfVSsm2tvxLIbthndGZ4xIblq168TWR5bnfKdYpbxv6DBWUrMrFPng0mW7ady7o4W+LA+aJ\r
+ n55/1Zjitr5pbqmwEktxRqKhFnNRcSIAHdCTPxUDAAA=\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: Thu, 24 Oct 2013 21:08:49 -0000\r
+\r
+There might be a problem with this patch. Directory entries that are\r
+*symlinks* to other directories do not increase the containing\r
+directory's link count, but we do count them as directories in\r
+add_files pass 1 and traverse in to them. Hence, if you had a\r
+directory that contained no sub-directories, but did contain symlinks\r
+to other directories, we would fail to notice changes in the symlinked\r
+directories.\r
+\r
+We could check if the database thinks there are sub-directories and\r
+only bail early if the directory is unchanged and *both* the file\r
+system and the database think there are no sub-directories.\r
+\r
+Quoth myself on Oct 24 at 4:33 pm:\r
+> This can substantially reduce the cost of notmuch new in some\r
+> situations, such as when the file system cache is cold or when the\r
+> Maildir is on NFS.\r
+> ---\r
+> notmuch-new.c | 20 ++++++++++++++++++++\r
+> 1 file changed, 20 insertions(+)\r
+> \r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index faa33f1..364c73a 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -323,6 +323,26 @@ add_files (notmuch_database_t *notmuch,\r
+> }\r
+> db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;\r
+> \r
+> + /* If the directory is unchanged from our last scan and has no\r
+> + * sub-directories, then return without scanning it at all. In\r
+> + * some situations, skipping the scan can substantially reduce the\r
+> + * cost of notmuch new, especially since the huge numbers of files\r
+> + * in Maildirs make scans expensive, but all files live in leaf\r
+> + * directories.\r
+> + *\r
+> + * To check for sub-directories, we borrow a trick from find,\r
+> + * kpathsea, and many other UNIX tools: since a directory's link\r
+> + * count is the number of sub-directories (specifically, their\r
+> + * '..' entries) plus 2 (the link from the parent and the link for\r
+> + * '.'). This check is safe even on weird file systems, since\r
+> + * file systems that can't compute this will return 0 or 1. This\r
+> + * is safe even on *really* weird file systems like HFS+ that\r
+> + * mistakenly return the total number of directory entries, since\r
+> + * that only inflates the count beyond 2.\r
+> + */\r
+> + if (directory && fs_mtime == db_mtime && st.st_nlink == 2)\r
+> + goto DONE;\r
+> +\r
+> /* If the database knows about this directory, then we sort based\r
+> * on strcmp to match the database sorting. Otherwise, we can do\r
+> * inode-based sorting for faster filesystem operation. */\r