msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.29k stars 486 forks source link

msys2.exe takes almost 40 seconds to launch #1785

Open rowet opened 4 years ago

rowet commented 4 years ago

On a windows 7 machine I have msys2 v20190524.0.0.20191030 installed by way of Chocolately. When I click the msys2 launcher or run msys2.exe on a command prompt, it takes a bit under 40 seconds for a bash prompt to appear on the screen. Is this normal?

How might I go about profiling this to see what is taking so long?

rowet commented 4 years ago

Is this the right place to file such an issue? It's not a "packages" thing.

StarWolf3000 commented 4 years ago

First, install MSYS2 by using the provided installer, and not some third-party package manager. Second, security software might scan your processes and tries to sandbox it, taking up additional time. Since the binaries from MSYS2 are not digitally signed and not in their databases, they're not trusted. I know that Avast can take some time to scan them.

schnedann commented 4 years ago

this is "normal" behavior to my knowledge. As stated a security software might add a lot to that issue: at work we have a antivirus which causes such bad timings. Try to execute "configure" for example. I once had a case, for the same peace of code: configure at work via msys2: more than 15minutes, at home without this antivirus, lets say 1-2minutes, and with a real linux less than 30 seconds...

So why things like msys are way slower as the same action on the same computer with linux (same issue for example with plotting in octave)? As far as I know its creating sub-processes on windows is slower in general plus the emulation of the Unix/linux forking - which has no equivalent in windows - is slow. so everything you do which needs sub-process creation is slow in msys2 compared to the same action on e.g. linux. And bad news: this is known for a long time now and to my knowledge there is no viable solution at hand.

rowet commented 4 years ago

The cisco amp security software on the machine does not show any notable resource usage (sfc.exe stays calm). I've asked the administrators about having msys2.exe whitelisted, however I have the scanning stuff misbehave before and use a lot of resources due to an unsigned program and this 40 second launch time isn't the sort of issue it causes. I've run vanilla cygwin on machines like this and never seen such slow launching.

If anyone has tips on how to profile the operation and be happy to provide hard data on what is going on. I just tried Process Monitor. The "fast io disallowed" events look a bit suspicious, but I don't know exactly what that means.

image

pnetherwood commented 4 years ago

I found that the delay was looking up the user credentials in Windows. The fix was to create your own /etc/passwd file and disable Windows credential database lookup:

if [ ! -f /etc/passwd ]; then 
  mkpasswd -l -c > /etc/passwd
  mkgroup -l -c > /etc/group
fi

if [ ! -f /etc/nsswitch.conf.dist ]; then 
  cp /etc/nsswitch.conf /etc/nsswitch.conf.dist
fi
sed 's/files db/files # db/' /etc/nsswitch.conf.dist > /etc/nsswitch.conf

It loads pretty much instantaneously for me now.

rowet commented 4 years ago

Confirmed. Loads near instantaneously for me now.