0

I recently switched from git bash on windows to using WSL2 almost exclusively.

The issue I am having is that my tab autocompletes for branches is insanely slow (in the seconds). Other autocomplete are fast, such as autocompleting git commands (git checko[TAB] would autocomplete to checkout without problem).

What can I do to isolate the problem or resolve ( less than 1 second to autocomplete) it?

efox29
  • 141
  • 1
  • 8
  • 1
    Are your files under `/mnt/c` (or another Windows drive)? if so, see if my answer to [this question](https://stackoverflow.com/q/68972448/11810933) helps you out. – NotTheDr01ds Dec 29 '21 at 05:31
  • Ya this is what it was. – efox29 Dec 29 '21 at 06:06
  • 1
    Is running `git for-each-ref --format='"%(refname)"' refs/heads` slow because that's what zsh uses? You can define your own `__git_branch_names()` function. If this is completion after `git checkout`, it completes more than just branch names and that could be where it gets slow. Is completion after `git switch` any better because that'll only be branches. Could be worth getting into the habit of using it instead for branch switching. – okapi Dec 29 '21 at 08:29
  • @okapi i just tried git switch and it doesn't suffer the same performance problems. I might need to just change my aliases for branch...or as a few ppl mentioned, roll my own – efox29 Dec 29 '21 at 20:56
  • @okapi and `git for-each-ref --format='"%(refname)"' refs/heads` is not slow...all refs display quick – efox29 Dec 29 '21 at 20:57
  • Completion after `git checkout` completes a number of other things: recent commits, tags, remote branches. It'd be useful to narrow down which is slow. You can disable them individually with the `tag-order` style. – okapi Dec 30 '21 at 22:33

2 Answers2

1

In order to autocomplete branches, bash has to parse files from the .git/refs directory or .git/packed-refs file, where the branch/tag names are stored.

If your repo is stored on the windows partition, this might be the reason why it's slow, as the windows/linux filesystem interop is known to be slow as of now.

In order to speed up the branch-name autocomplete, you could move the repo to the linux partition. If that's not an option, you could write your own autocomplete script that avoids IO with the windows filesystem.

0

git config --global oh-my-zsh.hide-info 1

Disable oh-my-zsh git prompt magic.

Root cause is WSL using the slow 9P protocol to access Windows drive.
ref. https://stackoverflow.com/a/68974497/135962

AndyWatts
  • 346
  • 2
  • 5