git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] mingw: improve performance of mingw_unlink()
@ 2020-08-17 10:37 Johannes Schindelin via GitGitGadget
  0 siblings, 0 replies; only message in thread
From: Johannes Schindelin via GitGitGadget @ 2020-08-17 10:37 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Jeff Hostetler

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-17 10:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 10:37 [PATCH] mingw: improve performance of mingw_unlink() Johannes Schindelin via GitGitGadget

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git