{"thread":{"id":"54055","subject":"[PATCH] mingw: improve performance of mingw_unlink()","startedAt":"2020-08-17T10:37:07Z","lastAt":"2020-08-17T10:37:07Z","messageCount":1,"participants":["Johannes Schindelin via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"403811","messageId":"pull.704.git.1597660622615.gitgitgadget@gmail.com","threadId":"54055","inReplyTo":null,"subject":"[PATCH] mingw: improve performance of mingw_unlink()","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-17T10:37:02Z","receivedAt":"2020-08-17T10:37:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate mingw_unlink() to first try to delete the file with existing\npermissions before trying to force it.\n\nWindows throws an error when trying to delete a read-only file.  The\nmingw_unlink() compatibility wrapper always tries to _wchmod(666) the\nfile before calling _wunlink() to avoid that error.  However, since\nmost files in the worktree are already writable, this is usually\nwasted effort.\n\nUpdate mingw_unlink() to just call DeleteFileW() directly and if that\nsucceeds return.  If that fails, fall back into the existing code path\nto update the permissions and use _wunlink() to get the existing\nerror code mapping.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    Windows: improve checkout performance with large numbers of files\n    \n    Jeff Hostetler contributed this patch to Git for Windows a while ago\n    after measuring ~15% improvement\n    [https://github.com/microsoft/git/pull/264#issuecomment-617216583] with\n    a very, very large worktree:\n    \n    > I ran a series of timing tests on the Office repo on my Z440 desktop.\n    > This was a full enlistment at HEAD. I ran git sparse-checkout disable \n    > to populate the entire worktree and then git sparse-checkout init\n    > --cone to delete everything except the files at root. I repeated that\n    > sequence 3 times.\n    >\n    > Each init needed to delete about 2.1M files.\n    >\n    > git sparse-checkout init\n    >\n    > old: 636.1s, 638.3s, 637.2s, 637.2s new: 535.9s, 544.8s, 533.3s,\n    > 538.0s\n    >\n    > In this example, run time was decreased by 15%.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-704%2Fdscho%2Funlink-perf-gfw-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-704/dscho/unlink-perf-gfw-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/704\n\n compat/mingw.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 4454b3e67b..a00f331230 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -290,6 +290,9 @@ int mingw_unlink(const char *pathname)\n \tif (xutftowcs_path(wpathname, pathname) < 0)\n \t\treturn -1;\n \n+\tif (DeleteFileW(wpathname))\n+\t\treturn 0;\n+\n \t/* read-only files cannot be removed */\n \t_wchmod(wpathname, 0666);\n \twhile ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {\n\nbase-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n-- \ngitgitgadget\n"}]}