Skip to content

Git Execution Blocks UI Thread #1974

Closed

Description

@alex-courtis

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

  1. added
    bug
    on Feb 6, 2023
  2. alex-courtis commented on Feb 6, 2023

    @alex-courtis
    MemberAuthor

    Replace git command with a 2 sec sleep

    1974.patch.txt

  3. 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.

  4. 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
  5. added 2 commits that reference this issue on Feb 12, 2023
  6. 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

  7. added a commit that references this issue on Feb 12, 2023
  8. 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
  9. alex-courtis commented on Mar 27, 2023

    @alex-courtis
    MemberAuthor

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

  10. 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.

  11. added 2 commits that reference this issue on Apr 3, 2023
  12. added a commit that references this issue on Apr 3, 2023
  13. alex-courtis commented on Apr 3, 2023

    @alex-courtis
    MemberAuthor

    experiment running

  14. 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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions