microsoft / git

A fork of Git containing Microsoft-specific patches.
http://git-scm.com/
Other
763 stars 92 forks source link

Redirecting stdout causes the program to stop for 40 seconds #590

Open miku1958 opened 1 year ago

miku1958 commented 1 year ago

Setup

$ git --version --build-options

git version 2.40.1.vfs.0.2
cpu: x86_64
built from commit: 59bc9667c84164a4ad879d9b424687ca631f01b3
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon

Scalar

macOS 13.4.1

Details

bash

#!/bin/bash
start=$(date +%s)

output=$(/usr/local/bin/git checkout 2>&1)

end=$(date +%s)

diff=$((end - start))
echo "git $@ | cost: $diff s"

It completes just as quickly as running git checkout directly

when I use /usr/local/bin/git checkout in the script, it takes 6 s, but when I try to save the output to a variable, it takes 45 s

I also change /usr/local/bin/git to /usr/bin/git to save the output, and Apple-git finish it immediately.

dscho commented 1 year ago

Is this really reproducible? I would expect the git checkout to be relatively slow when e.g. FSMonitor just started up, but to be fast otherwise.