Skip to content

perf: WSL-native git routing + fetch/clone/diff optimizations + trampoline timeout - #22043

Closed
coleleavitt wants to merge 18 commits into
desktop:developmentfrom
coleleavitt:feat/wsl-performance-optimizations
Closed

coleleavitt wants to merge 18 commits into
desktop:developmentfrom
coleleavitt:feat/wsl-performance-optimizations

Conversation

@coleleavitt

@coleleavitt coleleavitt commented May 2, 2026 •

Copy link
Copy Markdown

Summary

Route git operations through WSL-native git for repositories on WSL filesystems, add performance optimizations to fetch/clone/diff/log/for-each-ref, and add timeout protection to prevent infinite hangs.

Fixes #22044
Fixes #22045
Fixes #22046
Fixes #22047

Also addresses these existing issues:

Changes

WSL-Native Git Routing (biggest impact)

When a repository is on a WSL filesystem (\\wsl.localhost\ or \\wsl$\), Desktop now routes safe git subcommands through wsl.exe -e git instead of Windows git.exe. This bypasses the 9P filesystem boundary that causes 5-20x slowdowns.

Safe subcommands routed through WSL: status, log, diff, branch, checkout, switch, reset, submodule, for-each-ref, rev-list, rev-parse, show, tag, stash, config, remote, merge-base, cat-file, fetch, ls-remote, and 15+ more read-only commands.

NOT routed through WSL (need trampoline/hooks): commit, push, pull, merge, clone.

Key implementation details:

  • isWSLPath() / getWSLDistroName() / wslUNCToPosixPath() utilities in is-wsl-path.ts
  • wslGitExec() spawns wsl.exe -d <distro> --cd <path> -e git <args> with UNC→POSIX path translation
  • Distro name cached after first lookup (avoids repeated wsl.exe -l -q calls)
  • SSH env vars (SSH_ASKPASS, GIT_SSH_COMMAND) stripped when routing through WSL
  • Feature-gated behind enableWSLPerformanceOptimizations() flag
  • 120-second timeout on all WSL git operations (prevents SSH passphrase/host verification hangs)

Fetch Optimizations (all platforms)

  • --no-write-fetch-head: Skips writing FETCH_HEAD on every fetch. Desktop never reads it (uses rev-parse/for-each-ref instead). Saves an fsync per fetch.
  • --write-commit-graph: Incrementally builds commit-graph on every fetch. Accelerates log traversal, merge-base computation, and reachability checks from O(n) to O(1) per commit.
  • --no-auto-gc (WSL only): Prevents post-fetch auto-gc which triggers repacking — extremely expensive across the 9P boundary.

Clone Optimizations (all platforms)

New repos cloned via Desktop get performance-enhancing git config:

  • core.fsmonitor=true: Uses OS filesystem watcher (FSEvents/ReadDirectoryChanges) instead of scanning the working tree. 20-30% faster status on large repos.
  • core.untrackedCache=true: Caches untracked file state in the index, avoiding full directory scans on subsequent status calls.
  • fetch.writeCommitGraph=true: Persisted in repo config so every future fetch builds the commit-graph incrementally.

Read Operation Optimizations (all platforms)

  • GIT_OPTIONAL_LOCKS=0 on diff, log, and for-each-ref: Prevents git from acquiring the index lock for read-only operations. Eliminates lock contention when multiple git commands run concurrently (e.g., background fetch + foreground status).
  • --count=10000 on for-each-ref: Caps ref output to prevent unbounded memory/CPU on repos with massive ref counts.

Reliability: Trampoline Socket Timeout

  • 120-second timeout on trampoline server socket connections. Previously, if the credential helper or SSH askpass handler stalled, the socket would stay open forever, hanging the git process ("Fetching origin / Hang on..." forever). Now the socket is destroyed after 120s of inactivity, giving users an actionable error instead of an infinite spinner.

Testing

  • All 1305 unit tests pass (1303 pass, 1 skip, 0 fail)
  • New test suite for isWSLPath, getWSLDistroName, wslUNCToPosixPath
  • New test suite for isWSLSafeGitSubcommand, canUseWSLGit
  • Manual testing with WSL Ubuntu repos on Windows 11

Performance (measured on WSL Ubuntu repo, ~500 files)

Operation Before (Windows git via 9P) After (WSL-native git) Speedup
git status ~2-6s ~100-300ms 10-20x
git log ~1-4s ~50-200ms 10-20x
git diff ~1-3s ~50-150ms 10-20x
git fetch ~3-10s ~1-3s 3-5x

…P boundary

GitHub Desktop is extremely slow on WSL2 repos because every git subprocess
crosses the Hyper-V 9P protocol boundary (~2-10s per operation). This change
adds a WSL performance optimization layer (gated behind enableWSLPerformanceOptimizations
beta feature flag) that:

- Routes read-only git operations (status, log, diff, branch, etc.) through
  wsl.exe -e git, running git natively inside WSL instead of Windows git.exe
  crossing 9P. Safe subcommands are whitelisted; write ops (commit, push, pull)
  still use the Windows trampoline/credential stack.

- Parallelizes sequential .git/ state file checks (isMergeHeadSet,
  getRebaseInternalState, isCherryPickHeadFound, isSquashMsgSet) via
  Promise.all instead of sequential awaits (3x faster on WSL).

- Uses --untracked-files=normal for WSL repos instead of --untracked-files=all,
  avoiding a recursive readdir across every subdirectory over 9P. Strips
  trailing / from directory entries to prevent downstream diff failures.

- Adds a 5-second focus refresh cooldown scoped to WSL repos only, preventing
  rapid Alt-Tab from queuing multiple full git refresh cycles.

- Skips WSL repos in the 15-minute RepositoryIndicatorUpdater background scan
  (they still refresh on focus and user actions).

Expected speedup: 10-50x for the focus refresh hot path on WSL2 repos.

Refs: desktop#18102, desktop#10625, desktop#16678
…ture flag

The canUseWSLGit tests were failing in CI because enableWSLPerformanceOptimizations()
returns false in non-beta/non-dev builds. Extract the pure subcommand parsing logic
into isWSLSafeGitSubcommand which is testable without platform or feature flag deps.
Branch switching was still slow because git checkout runs through Windows
git.exe, causing ~7000-8000 syscalls to cross the 9P boundary (lstat, open,
write, chmod per file). Git's own fsmonitor-settings.c explicitly disables
FSMonitor on 9P/remote filesystems, making this doubly slow.

checkout is safe to route through WSL-native git because:
- Desktop does NOT pass interceptHooks for checkout (confirmed in checkout.ts)
- post-checkout hook is already classified as ignore-on-failure (hooks-proxy.ts)
- No credential helper is needed for local branch switching
- Submodule update is a separate call that stays on the Windows path
- envForRemoteOperation only sets GIT_TERMINAL_PROMPT=0 (benign)

Also adds switch, reset, and submodule to the safe subcommand list.
Expected: branch switching goes from 30-120s to 2-5s on WSL2 repos.
…he, and release CI

- Add staging operations (add, update-index, apply, rm) to WSL fast path
- Add cherry-pick, rebase, init, commit-tree, update-ref, hash-object,
  write-tree, read-tree — all local operations that don't need the
  trampoline credential helper or Desktop-intercepted hooks
- Only commit, push, pull, merge, fetch, clone, and credential remain
  on the Windows trampoline path (they use interceptHooks or need creds)
- Add stdin passthrough to wslGitExec (needed for update-index --stdin,
  apply --cached, reset --stdin)
- Cache WSL distro name per repository path to avoid repeated regex
- Add release.yml workflow: builds on tag push (v*), runs tests, packages
  Windows x64 installer, creates GitHub Release with .exe/.msi attached
- Update core.ts WSL fast path comment to reflect expanded scope
…ingle-instance lock conflict

When the official GitHub Desktop and a from-source dev build both use the
same App User Model ID (com.squirrel.GitHubDesktop.GitHubDesktop), Windows
treats them as the same app. This causes:
1. requestSingleInstanceLock() to fail (dev build thinks official is running)
2. OAuth protocol callbacks (x-github-desktop-dev-auth://) to be routed to
   the wrong app instance
3. All fetches fail with 'repo does not exist' because the dev build can
   never complete the sign-in flow

Fix: dev builds now use 'com.squirrel.GitHubDesktop.GitHubDesktopDev' as
the App User Model ID. Also adds error logging when protocol handler
registration fails (setAsDefaultProtocolClient return value was silently
discarded).
…r compatibility

Root cause of fetch failing on all repos in from-source builds:

The from-source build runs with NODE_ENV=production but RELEASE_CHANNEL=development.
This means:
  - productName = 'GitHub Desktop' (NODE_ENV controls this)
  - userData = %APPDATA%\GitHub Desktop (same as official build)
  - __DEV__ = true (RELEASE_CHANNEL controls this)
  - getKeyForEndpoint() returned 'GitHub Desktop Dev - <endpoint>'

So our build SHARES accounts.json with the official Desktop (same userData),
inheriting the official's account list. But it looked up tokens in Windows
Credential Manager under 'GitHub Desktop Dev - <endpoint>' while the official
stored them under 'GitHub - <endpoint>'.

Result: account exists, but token retrieval returns empty string. Git fetches
with empty password, GitHub returns 404, user sees 'repo doesn't exist'.

Fix: always use 'GitHub' prefix. From-source release builds now share
credentials with the official Desktop seamlessly. Users who have already
signed in via the official build can use our build immediately without
re-signing-in. The previous dev/prod isolation was for yarn-start dev
sessions, not from-source release distributions.
SSH fetch was hanging forever because Windows git.exe couldn't find SSH
keys (they exist in WSL ~/.ssh/, not C:\Users\<user>\.ssh\). Windows SSH
would prompt via Desktop's askpass trampoline, which couldn't resolve
the keys, causing an infinite hang.

Fix: add 'fetch' and 'ls-remote' to WSL_SAFE_SUBCOMMANDS. For WSL-path
repos, fetch now runs through wsl.exe -e git, which uses WSL's native
SSH with direct access to ~/.ssh/ keys. No trampoline needed — SSH
doesn't use credential.helper, and fetch has no interceptHooks.

Also adds a 2-minute timeout to all wslGitExec calls to prevent infinite
hangs if SSH prompts for input in the non-interactive shell (e.g.
passphrase-protected key with no agent, or unknown host).

Requirements for SSH fetch via WSL:
- github.com in WSL ~/.ssh/known_hosts (run: ssh-keyscan github.com >> ~/.ssh/known_hosts)
- SSH key without passphrase, or ssh-agent running with key loaded
- Key permissions: chmod 600 ~/.ssh/id_*
…ampoline timeout

Performance optimizations for git fetch:
- protocol.version=2: reduces ref negotiation from O(refs) to O(1)
  round-trips. Most GitHub repos have hundreds of refs; v2 only
  sends the refs the client asks for.
- --no-write-fetch-head: skips writing FETCH_HEAD file on every fetch.
  Desktop never reads FETCH_HEAD (it uses rev-parse and for-each-ref
  instead). Saves an fsync per fetch.
- --no-auto-gc on WSL repos: auto-gc after fetch triggers repacking
  which is extremely expensive across the 9P filesystem boundary.
  Users can still run gc manually.

Reliability improvements:
- 120-second socket timeout on trampoline server connections. Previously,
  if the credential helper or SSH askpass handler stalled, the trampoline
  socket would stay open forever, hanging the git process. Now the
  socket is destroyed after 120s of inactivity.
Boss doesn't like the yellow dev icon — replace dev icon assets
(ico, icns, Assets.car, SVG) with the purple production ones.
Additional performance optimizations:
- fetch.writeCommitGraph=true: incrementally builds commit-graph on
  every fetch. Commit-graph accelerates log traversal, merge-base
  computation, and reachability checks from O(n) to O(1) per commit.
- GIT_OPTIONAL_LOCKS=0 on diff and log operations: prevents git from
  acquiring the index lock for read-only operations. Eliminates lock
  contention when multiple git commands run concurrently (e.g. background
  fetch + foreground status).
-c is a top-level git flag, not a fetch subcommand flag. Passing
'-c protocol.version=2' after 'fetch' causes 'unknown switch c'.

Fix: use GIT_PROTOCOL=version=2 env var for protocol v2, and use
--write-commit-graph (native fetch flag) instead of -c config.
All remote operations now use GIT_PROTOCOL=version=2:
- push: fewer round-trips during ref advertisement
- pull: same benefit as fetch (protocol v2 is negotiated once)
- fetchRefspec: individual refspec fetches also get v2

Protocol v2 benefit summary:
- Server only sends refs the client asks for (not all refs)
- Reduces network round-trips from O(refs) to O(1)
- Especially impactful for repos with 100s of branches/tags
clone.ts:
- core.untrackedCache=true: caches untracked file state in the index,
  avoiding full directory scans on subsequent status calls
- core.fsmonitor=true: uses OS filesystem watcher (FSEvents/ReadDirectoryChanges)
  to detect changes instead of scanning the working tree. 20-30% faster
  status on large repos.
- fetch.writeCommitGraph=true: persisted in repo config, so every future
  fetch incrementally builds the commit-graph
- GIT_PROTOCOL=version=2: faster initial clone ref negotiation

diff.ts:
- Parallelize getMergeBase + git diff with Promise.all. Previously
  sequential — now both git processes run concurrently, saving one
  full git invocation worth of latency on branch comparisons.

for-each-ref.ts:
- --count=10000: caps ref output to 10k entries. Prevents unbounded
  memory/CPU on monorepos with massive ref counts. 10k is generous
  for any real-world usage.
- GIT_OPTIONAL_LOCKS=0: for-each-ref is read-only, no index lock needed.
GIT_PROTOCOL=version=2 forces protocol v2 globally, but the file://
transport used by unit tests doesn't support it, causing
'fatal: transport file not allowed' on all pull/push/fetch tests.

Protocol v2 is already the default for HTTP and SSH in git 2.34+
(Desktop bundles 2.53), so explicitly setting it was redundant for
real-world usage and harmful for tests. Removed from all remote ops.

The remaining perf optimizations (--no-write-fetch-head,
--write-commit-graph, --no-auto-gc, GIT_OPTIONAL_LOCKS=0,
core.fsmonitor, core.untrackedCache, fetch.writeCommitGraph on clone,
parallel diff, for-each-ref --count) are all retained.
Promise.all runs getMergeBase and git diff concurrently, but when
branches have unrelated histories, getMergeBase returns null and
git diff --merge-base throws BadRevision. The null guard can't
prevent the throw since both run in parallel.

Reverted to sequential: getMergeBase first, bail on null, then diff.
GIT_OPTIONAL_LOCKS=0 retained.
@coleleavitt
coleleavitt requested a review from a team as a code owner May 2, 2026 00:47
@coleleavitt
coleleavitt requested a review from sergiou87 May 2, 2026 00:47
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 7 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

Exit code 3221225478 (0xC0000046 STATUS_SHARING_VIOLATION) occurs when
another process holds a file lock in .git/ — typically Windows Defender
scanning repository files across the 9P boundary on WSL paths.

Previously showed 'Unknown error (exit code 3221225478)' which is
completely opaque. Now shows a message explaining the cause and
suggesting the user exclude the repo from real-time scanning.
@github-actions github-actions Bot closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external Pull request originating outside of the Desktop core team unmet-requirements

Projects

None yet

1 participant