Skip to content

feat(#3394): experiment: async first git load, see :help nvim_tree.config.experimental, discuss at https://github.com/nvim-tree/nvim-tree.lua/issues/3397 - #3395

Merged
alex-courtis merged 4 commits into
nvim-tree:masterfrom
tomo-2525:feat/git-async-load
Nov 27, 2026

Conversation

@tomo-2525

Copy link
Copy Markdown
Contributor

resolves #3394

Design

Opening a large repository of my notes was slow, so I wanted the git status to be loaded lazily.

  • This is an experimental option, experimental.git_async_load, off by default.
  • The tree is still built synchronously (Explorer:_load is unchanged), and only the git status is loaded later. This keeps the change small and inside lua/nvim-tree/git/init.lua.
  • While the git status is loading, no git status is shown, git_ignored files are shown and git_clean hides every file. I think a short time without git status is better than Nvim blocking.

AI usage

AI used: Claude (Claude Opus 5.5) in Claude Code. The code was also reviewed by another Claude model (Claude Fable 5.2).

All code and documentation in this PR were written by Claude. None was written by me.

What I did:

  • noticed the slow startup and asked Claude to investigate the cause
  • decided on the asynchronous approach, and to raise the issue and this PR
  • chose the design decisions: an experimental option, keeping the code in git/init.lua, and following git.timeout
  • asked Claude for a second review; Claude had Claude Fable review the code and fixed the bug it found

Testing

Claude ran these tests and I reviewed the results.

  • Time until opening the tree returns, in a repository with about 27,000 tracked files and 12,600 directories: 1.6 - 1.9s with the option off, 0.05 - 0.2s with it on.
  • After the git status has loaded, the tree lines, git highlights and cursor line were compared with the option off and on, in 16 combinations: a small test repository and the large repository, git_ignored and git_clean on and off, and opening at the root, expanding after loading, or opening a file with find_file. 14 were identical. The other 2 are the known difference documented in the option: with git_clean, find_file cannot find the file while the status is loading.
  • The bug found in the review was reproduced: a directory opened and closed while loading kept the old children. The option off and on are identical after the fix.
  • make lint, make check, make style, make style-doc, make format-check and make help-update pass.

I also tried it with my own configuration in the large repository, and opening it is clearly faster.

tomo-2525 and others added 2 commits November 22, 2026 15:01
…nc git load

Closed directories explored while git status was in flight kept the
children filtered against the empty status, and reopening them does not
explore them again. Walk every explored directory instead of the open
ones only.

Document that git.timeout still applies and that reloads still block,
and add line comments to the changed functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 06:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved Git-refresh issues can leave hidden directories stale, overwrite grouped submodule statuses and filters, and allow older initial-scan results to replace newer updates.

3 open issues
What changed in this PR

Adds an opt-in asynchronous initial Git status load to reduce blocking when opening large repositories, addressing #3394 while keeping tree construction synchronous.

Changes:

  • Adds experimental.git_async_load, disabled by default.
  • Loads initial Git status in the background, then refreshes explored directories and restores cursor focus.
  • Documents temporary filter behavior, timeout handling, and synchronous reloads.
File Description
lua/​nvim-tree/​git/​init.lua Implements asynchronous initial loading, completion refreshes, and shared watcher creation.
lua/​nvim-tree/​config.lua Adds the disabled-by-default experimental option.
lua/​nvim-tree/​_meta/​config/​experimental.lua Defines and documents the option and its limitations.
doc/​nvim-tree-lua.txt Updates help text and the default configuration example.

Review effort: Balanced

Comment thread lua/nvim-tree/git/init.lua Resolved
Comment thread lua/nvim-tree/git/init.lua Resolved
Comment thread lua/nvim-tree/git/init.lua Resolved
@tomo-2525

Copy link
Copy Markdown
Contributor Author

The Copilot review on this PR was requested automatically by my GitHub settings. I did not intend it.
I tried to remove it but could not.
I have turned the setting off, so it will not happen again.

Comment thread lua/nvim-tree/git/init.lua Resolved
Comment thread lua/nvim-tree/git/init.lua Resolved

@alex-courtis alex-courtis left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just fantastic, nice work!

Please:

  • Create a new issue similar to #3343, which will be pinned
  • Remove all code comments that should be PR inline comments e.g. -- moved unchanged from load_project, so that the synchronous and asynchronous loads share it They do not add any value for future maintainers, see similar #3388 (comment)

Next:

  • Merge with git_async_load = false
  • Change to git_async_load = true after several weeks
  • Finish the experiment and remove old codepaths

Testing notes:

  • git_async_load = false, working as normal
  • project load: statuses appear after tiny delay, ignored are hidden in directories and root
  • new git watcher working:
    • touch .git/config
    • git checkout dirty and clean
  • open an ignored file and :NvimTreeFindFile
    • focuses root
    • focues parent folder

Review notes, no action required

  • load_project_async calling reload_git_project is equivalent to the functionality at the end of the sync path of load_project
  • new create_git_watcher function is shifted unchanged from load_project
  • reload_project_nodes is the new functionality required for the async update, which does the minimum required by Explorer:explore, although the draw and focus are required at the end. draw is done only once, resulting in the minimum of 2 draws on load.

@alex-courtis

alex-courtis commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Remove all code comments that should be PR inline comments

Apologies, CONTRIBUTING was misleading and incorrect, updated:

ba85443

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@alex-courtis alex-courtis left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks @tomo-2525

Merged and released.

Pinned issue #3397 created, please watch this issue.

It's enable for me.

@alex-courtis alex-courtis changed the title feat(#3394): experimental async first git load feat(#3394): experiment: async first git load, see :help nvim_tree.config.experimental, discuss at https://github.com/nvim-tree/nvim-tree.lua/issues/3397 Nov 27, 2026
@alex-courtis
alex-courtis merged commit ab72983 into nvim-tree:master Nov 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experimental: load the git status of a project asynchronously on first display

3 participants