Skip to content

Git Execution Blocks UI Thread #1974

@alex-courtis

Description

@alex-courtis
Member

Description

Git operations block the UI thread whilst they are running.

Neovim version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Linux 6.1.9-arch1-1

nvim-tree version

02fdc26

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {
    git = {
      timeout = 3000,
    },
}
end

Steps to reproduce

Replace git job with "sleep 2"

Expected behavior

No response

Actual behavior

No response

Activity

alex-courtis

alex-courtis commented on Feb 6, 2023

@alex-courtis
MemberAuthor

Replace git command with a 2 sec sleep

1974.patch.txt

alex-courtis

alex-courtis commented on Feb 6, 2023

@alex-courtis
MemberAuthor

refresh_node is synchronous and the main codepath for git excecution, usually following debounce: https://github.com/nvim-tree/nvim-tree.lua/blob/master/lua/nvim-tree/explorer/reload.lua#L145

This could be made asynchronous as per #1870 or some simpler means.

alex-courtis

alex-courtis commented on Feb 7, 2023

@alex-courtis
MemberAuthor

Async/await is a possibility however adds complexity and is not yet available in nvim: neovim/neovim#19624

It looks like this one might be the winner: https://github.com/lewis6991/async.nvim It's more straightforward and complete that plenary's.

current control is OK: spawn git process, watcher timer to time out.

Runner.run can invoke a callback on OK/timeout passing raw output as per current return.

load_project_status is invoked only by Explorer:_load which can load the tree in the callback.

reload_project:

  • reload
    • reload_explorer can render in the callback using the event_running lock
    • reload_git can do the same
  • reload_and_get_git_project
    • refresh_node
      • refresh_nodes_for_path is problematic due to the iteration; it will probably be OK to callback individually
      • watcher can act inside the callback
added 2 commits that reference this issue on Feb 12, 2023
alex-courtis

alex-courtis commented on Feb 12, 2023

@alex-courtis
MemberAuthor

SIGINT timed out processes.

SIGKILL process that don't interrupt after a further git.timeout

added a commit that references this issue on Feb 12, 2023
36e29c3
alex-courtis

alex-courtis commented on Feb 12, 2023

@alex-courtis
MemberAuthor

Unfortunately callbacks from git runner are getting too deep into callback hell, specifically Explorer:_load

Alternatives:

  • Explorer:_load is synchronous, others are async
  • git status is always asynchronously drawn
alex-courtis

alex-courtis commented on Mar 27, 2023

@alex-courtis
MemberAuthor

core.init has too great a fanout to make Explorer:_load async.

alex-courtis

alex-courtis commented on Mar 27, 2023

@alex-courtis
MemberAuthor

Async watcher git execution for files is working. The same can be done for git watcher executions.

The above two are the only reactive git executions; all others are in response to a user action.

That should be sufficient as the perceived delays following user actions are less noticeable.

added 2 commits that reference this issue on Apr 3, 2023
added a commit that references this issue on Apr 3, 2023
alex-courtis

alex-courtis commented on Apr 3, 2023

@alex-courtis
MemberAuthor

experiment running

added 2 commits that reference this issue on Apr 22, 2023
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alex-courtis

      Issue actions

        Git Execution Blocks UI Thread · Issue #1974 · nvim-tree/nvim-tree.lua