title: Git difftool ridiculously slow in Cygwin/MinGW
body: <p>I noticed that <code>git difftool</code> is very slow. An delay of about 1..2 seconds appears between each diff invocation. </p>
  
  <p>To benchmark it I have written a custom <code>difftool</code> command: </p>
  
  <pre><code>#!/bin/sh
  echo $0 $1 $2
  </code></pre>
  
  <p>And configured Git to use this tool in my <code>~/.gitconfig</code></p>
  
  <pre><code>[diff]
      tool = mydiff
  [difftool "mydiff"]
      prompt = false
      cmd = "~/mydiff \"$LOCAL\" \"$REMOTE\""
  </code></pre>
  
  <p>I tested it on the Git sources:</p>
  
  <pre><code>$ git clone https://github.com/git/git.git
  $ cd git
  $ git rev-parse HEAD
  1bc8feaa7cc752fe3b902ccf83ae9332e40921db
  $ git diff head~10 --stat --name-only | wc -l
  23
  </code></pre>
  
  <p>When I time a <code>git difftool</code> with <code>259b5e6d33</code>, the result is ridiculously slow: </p>
  
  <pre><code>$ time git difftool 259b5
  mydiff /dev/null Documentation/RelNotes/2.6.3.txt
  ...
  mydiff /tmp/mY2T6l_upload-pack.c upload-pack.c
  
  real    0m10.381s
  user    0m1.997s
  sys     0m6.667s
  </code></pre>
  
  <p>By trying a simpler script it goes much faster:</p>
  
  <pre><code>$ time git diff --name-only --stat 259b5 | xargs -n1 -I{} sh -c 'git show 259b5:{} &gt; {}.tmp &amp;&amp; ~/mydiff {} {}.tmp'
  mydiff Documentation/RelNotes/2.6.3.txt Documentation/RelNotes/2.6.3.txt.tmp
  mydiff upload-pack.c upload-pack.c.tmp
  
  real    0m1.149s
  user    0m0.472s
  sys     0m0.821s
  </code></pre>
  
  <p>What did I miss?</p>
  
  <p>Here the results I got</p>
  
  <pre><code>| Cygwin | Debian | Ubuntu | Method   |
  | ------ | ------ | ------ | -------- |
  | 10.381 |  2.620 | 0.580  | difftool |
  |  1.149 |  0.567 | 0.210  | custom   |
  </code></pre>
  
  <p>For the <code>Cygwin</code> results, I measured 2.8s spent in <code>git-difftool</code> and 7.5s spent in <code>git-difftool--helper</code>. The latter is 98 lines long. I don't understand why it is that slow. </p>