Subject: Speeding up diff on Windows

From: Gisle Vanem <[email-masked]>
Date: Tue, 15 Jun 2021 13:57:49 +0200

Hello list.

I feel a 'diff --recursive ..' takes way too much time
to diff 2 trees of a few 1000 files each.

Reading the MSDN docs for '_open()', the under-laying
cache-behaviour and the 'O_SEQUENTIAL' flag, it seems
sensible that the Windows "Cache Manager" [1] works
faster with the 'O_SEQUENTIAL' flag. So with this
little pseudo-patch of 'diff.c':

+#ifndef O_SEQUENTIAL
+#define O_SEQUENTIAL 0
+#endif
        /* Open the files and record their descriptors.  */

        int oflags = O_RDONLY | (binary ? O_BINARY : 0);
+      oflags |= O_SEQUENTIAL;
+
        if (cmp.file[0].desc == UNOPENED)
          if ((cmp.file[0].desc = open (cmp.file[0].name, oflags, 0)) < 0)

I seem to get the job done quicker. I cannot give any numbers on
the speed-increase. But others may have some comments?

[1] https://docs.microsoft.com/en-us/windows/win32/fileio/file-caching

-- 
--gv