Skip to content

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

Open

Description

@tomo-2525

Can this functionality be implemented utilising API?

No. The first git status of a project runs inside git.load_project, which is called from Explorer:_load
while the tree is built. No API can make that call asynchronous.

Is your feature request related to a problem? Please describe.

The first time nvim-tree shows a git repository, git.load_project runs git status synchronously,
and Nvim is blocked until it completes (GitRunner:wait).

nvim-tree runs git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u.
In a large repository both -u (all untracked files) and --ignored walk every directory,
as the untracked cache cannot be used with them.

Measured on a repository with about 27,000 tracked files and 12,600 directories
(macOS, Nvim 0.12.5, git with fsmonitor and untracked cache enabled):

git status options time
none 0.13s
-uall only 1.4s
--ignored=matching only 1.4 - 1.6s
both, as nvim-tree runs it 1.4 - 1.7s

When the tree is opened at startup beside a file (toggle({ focus = false, find_file = true })),
nothing is drawn until git status completes.

#1974 made the git watcher reloads asynchronous and noted that Explorer:_load has too great a fanout to be made async.
#3385 proposes making reload_explorer and reload_git asynchronous; it does not cover the first load.

Describe the solution you'd like

An experimental option, off by default, e.g. experimental.git_async_load.
It changes git.load_project only; Explorer:_load and explore stay synchronous:

  1. When the project is unknown, register an empty project and return it straight away, so the tree is drawn without git status.
    The registered project also prevents another git status for the same project while the first one runs.
  2. Run the same git status with the async GitRunner callback, as refresh_dir does.
  3. On completion, fill in the project, reload the explored directories of that project with Explorer:reload
    so that the git filters are applied, and keep the cursor on the same node.

With a prototype, opening the tree in the repository above takes 0.05 - 0.2s instead of 1.6 - 2.3s.
Once git status has completed, the rendered tree, git highlights and cursor line are identical to the synchronous load.
I compared them with git_ignored and git_clean on and off, with and without find_file.

Known differences while git status is running:

  • no git status is shown, git_ignored files are shown and git_clean hides every file
  • with git_clean, find_file cannot find the file at startup, so its directory is not opened

I will raise a PR with this prototype, referencing this issue.

Describe alternatives you've considered

  • git.disable_for_dirs for large repositories: loses the git status in the tree.
  • A larger git.timeout: prevents the git integration from being disabled, but the tree still blocks for the whole duration.
  • Opening the tree after UIEnter: the file is drawn first, but Nvim still blocks for the same time afterwards.

Additional context

I used an AI assistant (Claude) to investigate the code and to draft the prototype and this issue.
I have reviewed the content and will answer questions myself.

Activity

  1. added a commit that references this issue on Nov 22, 2026
  2. alex-courtis commented on Nov 24, 2026

    @alex-courtis
    Member

    Testing Notes

    Linux 7.3.5-arch1-1, ext4 on pcie5 disk

    core.fsmonitor and core.untrackedcache not enabled as fsmonitor not available for linux.

    linux source repo:

    : ; find . -type f | wc -l
    97298
    : ; find . -type d | wc -l
    6356
    : ; time git --no-optional-locks status --porcelain=v1 -z --ignored=matching -uall
    git --no-optional-locks status --porcelain=v1 -z --ignored=matching -uall  0.08s user 0.09s system 233% cpu 0.073 total
    : ; time git --no-optional-locks status --porcelain=v1 -z --ignored=matching
    git --no-optional-locks status --porcelain=v1 -z --ignored=matching  0.07s user 0.11s system 249% cpu 0.071 total
    : ; time git --no-optional-locks status --porcelain=v1 -z -uall
    git --no-optional-locks status --porcelain=v1 -z -uall  0.07s user 0.11s system 253% cpu 0.070 total
    : ; time git --no-optional-locks status --porcelain=v1 -z
    git --no-optional-locks status --porcelain=v1 -z  0.07s user 0.11s system 247% cpu 0.071 total

    This doesn't really prove anything, as the OS, filesystem and repo are different.

    nvim-tree performance matches above ~70ms

    : ; cat $XDG_STATE_HOME/nvim/nvim-tree.log | grep -v populate_children
    [2026-11-24 11:23:03] [profile] START core init /home/alex/src/linux
    [2026-11-24 11:23:03] [profile] START git toplevel git_dir /home/alex/src/linux
    [2026-11-24 11:23:03] [git] git -C /home/alex/src/linux rev-parse --show-toplevel --absolute-git-dir
    /home/alex/src/linux
    /home/alex/src/linux/.git
    [2026-11-24 11:23:03] [profile] END   git toplevel git_dir /home/alex/src/linux 1ms
    [2026-11-24 11:23:03] [profile] START git untracked /home/alex/src/linux
    [2026-11-24 11:23:03] [git] git -C /home/alex/src/linux config status.showUntrackedFiles
    [2026-11-24 11:23:03] [profile] END   git untracked /home/alex/src/linux 1ms
    [2026-11-24 11:23:03] [profile] START git sync job /home/alex/src/linux nil
    [2026-11-24 11:23:03] [git] running job with timeout 400ms
    [2026-11-24 11:23:03] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u
    [2026-11-24 11:23:03] [profile] END   git sync job /home/alex/src/linux nil 69ms
    [2026-11-24 11:23:03] [git] job success    /home/alex/src/linux nil
    [2026-11-24 11:23:03] [profile] START explore /home/alex/src/linux
    [2026-11-24 11:23:03] [profile] END   explore /home/alex/src/linux 3ms
    [2026-11-24 11:23:03] [profile] END   core init /home/alex/src/linux 78ms
    [2026-11-24 11:23:03] [profile] START view open
    [2026-11-24 11:23:03] [profile] END   view open 2ms
    [2026-11-24 11:23:03] [profile] START draw
    [2026-11-24 11:23:03] [profile] END   draw 5ms
    

    Where to?

    This is a change we should make.

    It doesn't matter that I can't replicate performance issues, you can, and I can review the change regardless.

    I've added millisecond log timings on the functional testing branch #3369 which could be picked to master if we need them.

    I'll get to a review as time permits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions