From patchwork Fri Nov 2 13:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Peart X-Patchwork-Id: 10665551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A70313BF for ; Fri, 2 Nov 2018 13:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27F272B761 for ; Fri, 2 Nov 2018 13:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 263182B822; Fri, 2 Nov 2018 13:31:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6C7F2B761 for ; Fri, 2 Nov 2018 13:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727502AbeKBWiL (ORCPT ); Fri, 2 Nov 2018 18:38:11 -0400 Received: from mail-qk1-f176.google.com ([209.85.222.176]:46334 "EHLO mail-qk1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbeKBWiL (ORCPT ); Fri, 2 Nov 2018 18:38:11 -0400 Received: by mail-qk1-f176.google.com with SMTP id q1so2928868qkf.13 for ; Fri, 02 Nov 2018 06:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rvwbkjUm5uw1S+93Gs+B5ND50M0Tj6i3uG4psYMeH9o=; b=YqSocV9v7/BcZ5/ndfCe/ItcWX4JpcAlPrK08480NVyydb2vm604jHsLQdFmleb/pn N8oMQaAzgUbWrMd8TQ3kiJeOkaWT/BORVvNml+4tai9ljg3otPSpBfKd6hLEon3VKOBJ Z13pxQd+gcnzQtc51IUFI3AMx34zbyMnpyDsvrACeeMcbfPFgfYndqS+tXz0PEKPwYNJ qdfs3bgv0EqVeJJXDmSVEDwMoyHyr853E2B3eovH8n040YkzAkCw4vW/0LOwOxSuZbkq 21THtD4O+Z6UTo0K2ZFaH42DjUR0EGwX47iIfq3kYtDR+qJx0/iZh03GiqmGO3Ta0Uum Pneg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rvwbkjUm5uw1S+93Gs+B5ND50M0Tj6i3uG4psYMeH9o=; b=qw14IXiJz2idLY/D0Nc/Da0yy1X6fFe84OVvxA8ymL574UTgqmRJSQsF8NxYmUE5c/ q1HKLeHgdjx1te6hE+SEfYoHFTGvoRN1YGFgcO6gvqacv9hr6W1O5ORps8ErLFXKPoNJ zBDIEOVjLcYpZNd18bYdtM0Y23BYtoMXtEfXcHuMXphHfMu4iG+IDvHTnbpqRuiBJhf+ eAawhYtY65teeKbK4A+2r2qftnSRgprlhp5iBlgKexQkyrjhvxSEooV/hPZpEHvgnzvh 9delX4U9KuGv5pG1ac4SpwZ2VxaSXsiVd8Wx8tB5uGuhFXmT9BgWMNMcLs2MzKR6iUA4 rzIg== X-Gm-Message-State: AGRZ1gIyGUoSlwpzsaYo8Oh0onTv9AixtpLkm7PVTBbD+uJgqWA5bhoT hOiXK9iyXYb80DVgCV6WNouJPOWu X-Google-Smtp-Source: AJdET5dtqXCYDI2D/YuK+3McJ/X4gyiaTfCjX298xcWH+//Eu2LxmQ3YTycOPklXEXyDzZAUhegdhg== X-Received: by 2002:aed:23d8:: with SMTP id k24-v6mr10944345qtc.39.1541165460738; Fri, 02 Nov 2018 06:31:00 -0700 (PDT) Received: from localhost.localdomain (70-33-148-227.unassigned.ntelos.net. [70.33.148.227]) by smtp.gmail.com with ESMTPSA id t36-v6sm21421010qth.83.2018.11.02.06.30.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Nov 2018 06:30:59 -0700 (PDT) From: Ben Peart To: benpeart@microsoft.com, git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v1] add: speed up cmd_add() by utilizing read_cache_preload() Date: Fri, 2 Nov 2018 09:30:50 -0400 Message-Id: <20181102133050.10756-1-peartben@gmail.com> X-Mailer: git-send-email 2.18.0.windows.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Peart During an "add", a call is made to run_diff_files() which calls check_remove() for each index-entry. The preload_index() code distributes some of the costs across multiple threads. Because the files checked are restricted to pathspec, adding individual files makes no measurable impact but on a Windows repo with ~200K files, 'git add .' drops from 6.3 seconds to 3.3 seconds for a 47% savings. Signed-off-by: Ben Peart --- Notes: Base Ref: master Web-Diff: https://github.com/benpeart/git/commit/fc4830b545 Checkout: git fetch https://github.com/benpeart/git add-preload-index-v1 && git checkout fc4830b545 builtin/add.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) base-commit: 4ede3d42dfb57f9a41ac96a1f216c62eb7566cc2 diff --git a/builtin/add.c b/builtin/add.c index ad49806ebf..f65c172299 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -445,11 +445,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) return 0; } - if (read_cache() < 0) - die(_("index file corrupt")); - - die_in_unpopulated_submodule(&the_index, prefix); - /* * Check the "pathspec '%s' did not match any files" block * below before enabling new magic. @@ -459,6 +454,10 @@ int cmd_add(int argc, const char **argv, const char *prefix) PATHSPEC_SYMLINK_LEADING_PATH, prefix, argv); + if (read_cache_preload(&pathspec) < 0) + die(_("index file corrupt")); + + die_in_unpopulated_submodule(&the_index, prefix); die_path_inside_submodule(&the_index, &pathspec); if (add_new_files) {