Why is stat slow?

Jakob Bohm jb-cygwin@wisemo.com
Mon Dec 22 13:57:45 GMT 2025


Dear Eliot,

As a longtime aficionado of these issues, Cygwin/MSYS2 stat() function 
is inherently slower than native Linux/WSL stat() syscall, because the 
native stat returns data already kept and cached for each file system 
inode/MFTE, while the Cygwin emulation goes through a lot of hoops to 
synthesize similar information from a variety of file system data .  The 
call path that uses GetFileInformationByHandle() is the closest to a 
native fast implementation, but unfortunately, most 21st century 
antivirus solutions tend to initiate a full "scan file on open to 
prevent passing infected data to vulnerable applications" cost when 
doing the proforma file open to get the file handle needed for the 
GetFileInformationByHandle() call or other low risk checks .

Another set of hoops in the stat() code is the synthesis of a simulated 
set of mode bits, which tends to bring in the entire ACL 
reinterpretation logic as well as detection of various symlink 
approximations (it would be faster to simply treat all "reparse points" 
as symlinks and add logic to readlink() that deals with the various 
native types, but that would loose the ability to create file system 
symlinks without the Administrator privilege of creating the more 
dangerous system objects also named "symlink" ).

If the false triggering of AV scanning can be avoided, streamlining the 
Cygwin stat() code could greatly speed up heavy users of stat() such as 
the find and du commands .


On 22/12/2025 06:15, Eliot Moss via Cygwin wrote:
> Dear Cygwin-ers --
>
> I'm sure this has been asked before, more than once, but I am again 
> wondering
> what, specifically, makes stat (the program, but presumably also the 
> syscall)
> substantially slower on Cygwin compared to stat on WSL2.  I am talking 
> about
> an external HDD (not solid state) on my D: drive.  It shows under WSL 
> 2 as
> /mnt/d like this (output of mount):
>
> D:\ on /mnt/d type 9p 
> (rw,noatime,aname=drvfs;path=D:\;uid=0;gid=0;symlinkroot=/mnt/,cache=5,access=client,msize=65536,trans=fd,rfd=5,wfd=5)
>
> On Cygwin it shows up like this (yes, mount shows two lines):
>
> D: on /cygdrive/d type ntfs (binary,notexec,posix=0,user)
> D: on /cygdrive/d type ntfs (binary,noacl,posix=0,user,noumount,auto)
>
> My /etc/fstab lines are:
>
> none /cygdrive cygdrive binary,noacl,posix=0,user 0 0
> d: /cygdrive/d ntfs binary,posix=0,user,auto,notexec 0 0
>
> (Presumably this has something to do with two mounts showing ...)
>
> On D; I have a folder with hundreds of 2Gb files (they are backups, 
> split into
> 2Gb portions).  On Cygwin
>
> time stat <the files> gives
>
> real    2m12.425s
> user    0m0.249s
> sys     0m1.312s
>
> A second run shortly after the first completes very quickly, 
> indicating the
> presence of a cache :-) .
>
> time stat <the files> on WSL2 gives:
>
> real    0m2.208s
> user    0m0.026s
> sys     0m0.149s
>
> This is after a reboot, so there is no caching available.  So, why is 
> Cygwin
> 60 times slower, even when WSL2 has the handicap of having to work 
> through the
> 9p adapter / COM surrogate?
>
> Mostly I am curious, but this is also relevant because I rsync this file
> collection to offsite storage, and the stat time is about what it 
> takes for
> rsync to start up - it needs to check file times and lengths.
>
> This makes me wonder if there is something we can do to make this 
> better, by
> figuring out what WSL2 / 9p are doing ...
>
> Best - Eliot Moss
>
Enjoy

Jakob
-- 
Jakob Bohm, CIO, Partner, WiseMo A/S.  https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded



More information about the Cygwin mailing list