Repository navigation
perf(shim): detach redirected children instead of giving them a hidden console - #751
Merged
Merged
Conversation
…n console `suppress_child_console_window` (niubash#379) chose CREATE_NO_WINDOW so a GUI parent spawning the shim with piped stdio does not make Windows allocate a *visible* console for the niu.exe child. That flag still allocates a console - a hidden one, with conhost.exe - on every invocation in exactly the case agents, CI and git hooks hit (all three streams redirected). With all three streams redirected the child has no console to inherit and does not need one, so DETACHED_PROCESS gives it that for free, and it keeps the anti-flash property: a console-subsystem child started with DETACHED_PROCESS gets no automatic console either. The gate is unchanged (all three streams non-console; an interactive session keeps the real console, as before), and so is cancellation: neither flag lets the child receive the parent's Ctrl+C, since a CREATE_NO_WINDOW child has a console of its own rather than the parent's. Measured here (median of 25, interleaved, all stdio redirected, NIU_SHELL pointed at hostname.exe so only the shim is timed): 22.9 ms -> 21.8 ms. The latency win is small - an earlier report credited this flag change with ~22 ms, which did *not* reproduce on this machine; conhost is evidently shared or warm. The real cost of a forwarding hop is the extra process, and the durable fix for `bash`/`sh` is a hardlink to the shell (unixwin/niubash#397), which leaves this shim as the fallback for layouts without hardlink support. What this change buys is that the fallback no longer allocates a console per invocation. Verified: piped stdin/stdout round-trip, exit-code passthrough (`exit 7` -> 7), face selection unchanged (`$0` = bash, POSIX off; sh.exe -> POSIX on), and no conhost process for the duration of a 2 s child (only niu.exe).
This was referenced Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to niubash#379, with an honest measurement.
What changes
suppress_child_console_windowsetsCREATE_NO_WINDOWwhen all three stdio streams are redirected, so a GUI parent spawning the shim does not make Windows allocate a visible console for theniu.exechild. That flag still allocates a console — a hidden one, withconhost.exe— on every invocation in exactly the case agents, CI and git hooks hit.With all three streams redirected the child has no console to inherit and does not need one, so
DETACHED_PROCESSgives it that for free, and it keeps the anti-flash property: a console-subsystem child startedDETACHED_PROCESSgets no automatic console either. The gate is unchanged (an interactive session keeps the real console). Cancellation is unchanged too: neither flag lets the child receive the parent's Ctrl+C, because aCREATE_NO_WINDOWchild has a console of its own rather than the parent's.Measured
Median of 25, interleaved, all stdio redirected,
NIU_SHELLpointed athostname.exeso only the shim is timed:CREATE_NO_WINDOW)DETACHED_PROCESS)The latency win is ~1 ms, not the ~22 ms an earlier report credited to this flag. That number did not reproduce here — conhost is evidently shared or already warm. Stating it plainly because the difference matters for where the real fix belongs.
Where the real fix is
A forwarding hop costs one extra process; the durable fix for
bash/shis a hardlink to the shell, which is unixwin/niubash#397 (merged). This shim stays the fallback for layouts without hardlink support (exFAT, network shares) — and this change means the fallback no longer allocates a console per invocation. That is the whole claim.Verified
echo data | shim -c cat), exit-code passthrough (exit 7→ 7),-carguments intact;$0=bashwith POSIX off,sh.exe→ POSIX on;conhostprocess for the duration of a 2 s child (onlyniu.exe), versus one hidden console before;cargo test --bin bash→ 4 passed.