Repository navigation
Conversation
On Windows, cobra checks before every command whether docker.exe was started from Explorer, to show a 'this is a command line tool' hint. The check calls syscall.Getppid and then looks the parent up by PID, and both take a snapshot of all running processes, which costs tens of milliseconds on a typical machine. A double-click never passes arguments, so only do the check when there are none. GitHub CLI does the same. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
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.
Summary
On Windows, cobra runs a "mousetrap" check before every command: if docker.exe was started from Explorer it prints "This is a command line tool" and exits. The check (
mousetrap.StartedByExplorer) callssyscall.Getppid()and then looks the parent up by PID, and on Windows both walk aCreateToolhelp32Snapshotof every running process. With ~530 processes on my machine that is 31-38 ms per docker command, includingdocker --version.A double-click never passes arguments, so this sets
cobra.MousetrapHelpText = ""when there are any, the same as GitHub CLI does ininternal/ghcmd/cmd.go. Started without arguments (double-click), the hint is shown as before. spf13/cobra#2545 proposes the same condition in cobra; this makes docker independent of when that lands.Measured on Windows 11 (i9-10900K), master built with and without the change (Go 1.27.3),
DOCKER_CONTEXT=default, 40 interleaved runs, median of paired differences with 95% confidence interval:docker --versiondocker context showThe saving grows with the number of running processes.
go test ./cmd/docker/passes (Linux).I used an AI assistant (GitHub Copilot) for the investigation and to help write this change; I reviewed and tested it.
Release notes (optional)