All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
	Jeff Hostetler <jeffhost@microsoft.com>
Subject: [PATCH] mingw: improve performance of mingw_unlink()
Date: Mon, 17 Aug 2020 10:37:02 +0000	[thread overview]
Message-ID: <pull.704.git.1597660622615.gitgitgadget@gmail.com> (raw)

From: Jeff Hostetler <jeffhost@microsoft.com>

Update mingw_unlink() to first try to delete the file with existing
permissions before trying to force it.

Windows throws an error when trying to delete a read-only file.  The
mingw_unlink() compatibility wrapper always tries to _wchmod(666) the
file before calling _wunlink() to avoid that error.  However, since
most files in the worktree are already writable, this is usually
wasted effort.

Update mingw_unlink() to just call DeleteFileW() directly and if that
succeeds return.  If that fails, fall back into the existing code path
to update the permissions and use _wunlink() to get the existing
error code mapping.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    Windows: improve checkout performance with large numbers of files
    
    Jeff Hostetler contributed this patch to Git for Windows a while ago
    after measuring ~15% improvement
    [https://github.com/microsoft/git/pull/264#issuecomment-617216583] with
    a very, very large worktree:
    
    > I ran a series of timing tests on the Office repo on my Z440 desktop.
    > This was a full enlistment at HEAD. I ran git sparse-checkout disable 
    > to populate the entire worktree and then git sparse-checkout init
    > --cone to delete everything except the files at root. I repeated that
    > sequence 3 times.
    >
    > Each init needed to delete about 2.1M files.
    >
    > git sparse-checkout init
    >
    > old: 636.1s, 638.3s, 637.2s, 637.2s new: 535.9s, 544.8s, 533.3s,
    > 538.0s
    >
    > In this example, run time was decreased by 15%.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-704%2Fdscho%2Funlink-perf-gfw-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-704/dscho/unlink-perf-gfw-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/704

 compat/mingw.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/compat/mingw.c b/compat/mingw.c
index 4454b3e67b..a00f331230 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -290,6 +290,9 @@ int mingw_unlink(const char *pathname)
 	if (xutftowcs_path(wpathname, pathname) < 0)
 		return -1;
 
+	if (DeleteFileW(wpathname))
+		return 0;
+
 	/* read-only files cannot be removed */
 	_wchmod(wpathname, 0666);
 	while ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {

base-commit: 878e727637ec5815ccb3301eb994a54df95b21b8
-- 
gitgitgadget

                 reply	other threads:[~2020-08-17 10:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=pull.704.git.1597660622615.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jeffhost@microsoft.com \
    --cc=johannes.schindelin@gmx.de \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.