On Tue, Dec 06, 2022 at 09:10:51AM +0900, Junio C Hamano wrote: > Taylor Blau <me@xxxxxxxxxxxx> writes: > > > So it appears that the old version is ever-so-slightly faster than the > > new one. But it's so noisy, and the regression is so small that it's > > hard to notice it at all. > > > > So I wouldn't strongly oppose the patch based on those numbers, but in > > principle it seems flawed. > > Thanks for writing and reviewing. > > As long as we were touching the function, I suspect that > the logic should become more like > > if (fd #0 is not open) > open /dev/null read-only and give it to fd #0 > if (fd #1 is not open) > open /dev/null write-only and give it to fd #1 > if (fd #2 is not open) > open /dev/null write-only and give it to fd #2 > > with opening of /dev/null optimized not to happen when not needed. Yeah, that would work, and it has the added benefit of not opening fd #0 with O_RDWR (though I kind of doubt that such a thing matters in practice). But it's still no better than the patch here in the happy case, since we still have to perform three fcntl() checks to figure out that all three descriptors are initialized as-expected (versus just one open() and close()). So I think your version is a slight improvement on Christian's, but I would just as soon stick with what we have. Thanks, Taylor