Cygwin speed

Christian Franke Christian.Franke@t-online.de
Wed Mar 7 20:13:00 GMT 2007


Christopher Layne wrote:
> On Fri, Mar 02, 2007 at 11:11:54AM -0800, Brian Dessent wrote:
>> Vinod Gupta wrote:
>>
>>> Cygwin was a slow by a factor of 3x. Is that normal?
>> Yes.  Emulation of POSIX functions which do not exist on Windows is
>> expensive.  Fork is especially bad, which is all you're really testing
>> there.
>
> Where is the *continual* fork in his script btw?

There is no fork at all, the script uses only builtin shell commands.

This command prints the fork() count of a script on Cygwin:

$ strace bash ./script.sh | grep -c 'fork: 0 = fork()'


One reason for the slow execution of the script are >8000000 context 
switches done by Cygwin.

Bash calls sigprocmask() before starting each command, even for builtin 
commands.
Cygwin's sigprocmask() unconditionally calls sig_dispatch_pending().
This is necessary because POSIX requires that at least one pending 
signal is dispatched by sigprocmask().
sig_dispatch_pending() sends a __SIGFLUSH* to self and this causes 2 
thread context switches: main->sig->main.

With the attached patch, sigprocmask() does nothing if the signal mask 
is not changed.
This reduces the context switches to <5000.
(Patch is only intended for testing, it at least breaks above POSIX rule)


I've run 4 tests scripts on 5 "platforms":

Test 1: Original script, but with [[...]] instead of [...]:

i=1000000
while [[ $i -gt 0 ]]; do
 j=$(((i/3+i*3)**3))
 i=$((i-1))
done

Test 2: Original script unchanged:

i=1000000
while [ $i -gt 0 ]; do
...

Test 3: Original script with /100 iterations and using command version 
of [ (test):

i=10000
while /usr/bin/[ $i -gt 0 ]; do
...

Test 4: A real world "./configure" script


Results on same AMD64 3200+ @2GHz, XP SP2:

|                 Runtime (seconds) of test
|                  1      2       3       4
-------------------------------------------
Cygwin 1.5.24-2   77     84     138      33
Cygwin +patch     38     46     138      33
Linux on Virt.PC: 49     57      62      22
Linux on VMware:  29     34      23      20
Linux native:     23     29       7       6

(Linux = grml 0.9 live CD)

Observations:
- Shell scripts with many builtin commands would benefit from a Cygwin 
optimization preventing unnecessary context switches ...
- ... but this might not help for most real world scripts.
- fork() on Linux is also considerably slower when running in a VM on 
Windows.
- Bash's builtin [[...]] is faster than [...]


Christian

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070307/07814a0c/attachment.txt>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list