Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvim-tree.git.utils has_cygpath executable check takes ~200ms #2459

Closed
jtledon opened this issue Oct 9, 2023 · 11 comments · Fixed by #2486
Closed

nvim-tree.git.utils has_cygpath executable check takes ~200ms #2459

jtledon opened this issue Oct 9, 2023 · 11 comments · Fixed by #2486
Labels
awaiting feedback bug Something isn't working OS Windows WSL specific to windows WSL

Comments

@jtledon
Copy link

jtledon commented Oct 9, 2023

Description

nvim-tree takes roughly 200ms to start.
I have narrowed the issue down to a specific executable check in nvim-tree.git.utils, on line 5:
local has_cygpath = vim.fn.executable "cygpath" == 1

setup.git.enable = false does not resolve the issue

Im wondering if it has something to do with how long it takes to complete to complete external commands in WSL.
I would love to see an additional option that would allow me to disable this check, and default it to 0.

nvt-startuptime.mp4

Neovim version

NVIM v0.9.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Windows 10 Vesion 22H2 OS Build 19045.3448 - WSL2 - Ubuntu 22.04.3 LTS

nvim-tree version

53b0bca

Clean room replication

Clean room replication:
I was unable to even see nvim-tree in the startup logs when using the cleanroom replication. If there is something I am doing wrong, please let me know and I can update my Issue.
Command I used: `nvim -n -u nvt-min.lua --startuptime time.log test.txt`

nvt-min.lua:

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

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
      "dstein64/vim-startuptime",
    },
    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 = {
                enable = false,
            },
            renderer = {
                icons = {
                    glyphs = {
                        git = {
                            unstaged = "!",
                            staged = "+",
                            unmerged = "^",
                            renamed = "#",
                            untracked = "?",
                            deleted = "d",
                            ignored = "-",
                        },
                    },
                },
            },
            filters = {
                git_ignored = false,
            },

            actions = {
                open_file = {
                    quit_on_open = true,
                    window_picker = {
                        enable = false,
                    },
                },
                expand_all = {
                    exclude = { ".git", "target", "build", "node_modules" },
                },
            },

            view = {
                width = {
                    min = 15,
                    max = 45,
                },
            },
            log = {
                enable = true,
                truncate = true,
                types = {
                    diagnostics = true,
                    git = true,
                    profile = true,
                    watcher = true,
                },
            },
        })
end


Profile logs:
[2023-10-08 21:36:42] [profile] START change dir /home/jl/.dotfiles/.nvim
[2023-10-08 21:36:42] [profile] START core init /home/jl/.dotfiles/.nvim
[2023-10-08 21:36:42] [watcher] Watcher:new '/home/jl/.dotfiles/.nvim' nil
[2023-10-08 21:36:42] [watcher] Event:new '/home/jl/.dotfiles/.nvim'
[2023-10-08 21:36:42] [watcher] Event:start '/home/jl/.dotfiles/.nvim'
[2023-10-08 21:36:42] [profile] START git toplevel git_dir /home/jl/.dotfiles/.nvim
[2023-10-08 21:36:42] [git] git -C /home/jl/.dotfiles/.nvim rev-parse --show-toplevel --absolute-git-dir
/home/jl/.dotfiles
/home/jl/.dotfiles/.git
[2023-10-08 21:36:42] [profile] END   git toplevel git_dir /home/jl/.dotfiles/.nvim 1ms
[2023-10-08 21:36:42] [profile] START git untracked /home/jl/.dotfiles
[2023-10-08 21:36:42] [git] git -C /home/jl/.dotfiles config status.showUntrackedFiles
[2023-10-08 21:36:42] [profile] END   git untracked /home/jl/.dotfiles 1ms
[2023-10-08 21:36:42] [profile] START git sync job /home/jl/.dotfiles nil
[2023-10-08 21:36:42] [git] running job with timeout 400ms
[2023-10-08 21:36:42] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u
 M .bash/.bashrc
 M .nvim/lua/ledon/plugins/nvim-tree.lua
!! .history/
[2023-10-08 21:36:42] [git] done
[2023-10-08 21:36:42] [profile] END   git sync job /home/jl/.dotfiles nil 57ms
[2023-10-08 21:36:42] [git] job success    /home/jl/.dotfiles nil
[2023-10-08 21:36:42] [watcher] git start
[2023-10-08 21:36:42] [watcher] Watcher:new '/home/jl/.dotfiles/.git' { "FETCH_HEAD", "HEAD", "HEAD.lock", "config", "index" }
[2023-10-08 21:36:42] [watcher] Event:new '/home/jl/.dotfiles/.git'
[2023-10-08 21:36:42] [watcher] Event:start '/home/jl/.dotfiles/.git'
[2023-10-08 21:36:42] [profile] START explore init /home/jl/.dotfiles/.nvim
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/HowToBuildNvimManutally.txt
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/HowToBuildNvimManutally.txt 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/README.md
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/README.md 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/after
[2023-10-08 21:36:42] [watcher] Watcher:new '/home/jl/.dotfiles/.nvim/after' nil
[2023-10-08 21:36:42] [watcher] Event:new '/home/jl/.dotfiles/.nvim/after'
[2023-10-08 21:36:42] [watcher] Event:start '/home/jl/.dotfiles/.nvim/after'
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/after 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/ftdetect
[2023-10-08 21:36:42] [watcher] Watcher:new '/home/jl/.dotfiles/.nvim/ftdetect' nil
[2023-10-08 21:36:42] [watcher] Event:new '/home/jl/.dotfiles/.nvim/ftdetect'
[2023-10-08 21:36:42] [watcher] Event:start '/home/jl/.dotfiles/.nvim/ftdetect'
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/ftdetect 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/init.lua
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/init.lua 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/lazy-lock.json
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/lazy-lock.json 0ms
[2023-10-08 21:36:42] [profile] START explore populate_children /home/jl/.dotfiles/.nvim/lua
[2023-10-08 21:36:42] [watcher] Watcher:new '/home/jl/.dotfiles/.nvim/lua' nil
[2023-10-08 21:36:42] [watcher] Event:new '/home/jl/.dotfiles/.nvim/lua'
[2023-10-08 21:36:42] [watcher] Event:start '/home/jl/.dotfiles/.nvim/lua'
[2023-10-08 21:36:42] [profile] END   explore populate_children /home/jl/.dotfiles/.nvim/lua 0ms
[2023-10-08 21:36:42] [profile] END   explore init /home/jl/.dotfiles/.nvim 0ms
[2023-10-08 21:36:42] [profile] END   core init /home/jl/.dotfiles/.nvim 61ms
[2023-10-08 21:36:42] [profile] START draw
[2023-10-08 21:36:42] [profile] END   draw 0ms
[2023-10-08 21:36:42] [profile] END   change dir /home/jl/.dotfiles/.nvim 67ms

Steps to reproduce

Opening neovim

Expected behavior

nvim-tree would have a minimal startup time

Actual behavior

nvim-tree has a significant startup time, far longer than anything else in my neovim config

@jtledon jtledon added the bug Something isn't working label Oct 9, 2023
@alex-courtis
Copy link
Member

alex-courtis commented Oct 15, 2023

Looking for cygpath is done by vim itself in various places e.g. https://github.com/neovim/neovim/blob/5d1c1da3c90adece96f491e7f12fd76c03a881c9/runtime/autoload/zip.vim although it looks to be lazy.

I don't have access to or expertise with windows so I am flying blind here.

Perhaps we can sort this out with feature flags.

Please open and :source this feature flag enumerator under WSL. I would be eternally grateful as that would be a very useful resource for future windows issues.

has.lua.gz

Please do the same for cygwin. Is that msys2?

Also powershell please.

@alex-courtis alex-courtis added the OS Windows WSL specific to windows WSL label Oct 15, 2023
@alex-courtis
Copy link
Member

Let's time the check directly. Please paste the following into executable_time.lua and :source that:

local before = vim.loop.hrtime()
vim.fn.executable "cygpath"
local after = vim.loop.hrtime()

print(after - before .. "ns")

On arch linux btrfs: 37300ns

@jtledon
Copy link
Author

jtledon commented Oct 16, 2023

When sourcing the has.lua under wsl, I get the following flags enabled:

wsl_has_list.log

When installing neovim in powershell using the official .msi installer for windows of neovim version 0.91 and sourcing the file:

pwsh_has_list.log

Additionally, when running the check directly with the commands provided for executable_time.lua, it came in at 364,133,189ns: just a little less than 10,000x slower. I ran it a few times to try and get an average and it hovered around the 355,000,000ns mark, which is higher than I was expecting because as shown in the initial video, performing the check had an impact of 0.2s and not 0.35s.

I am admittedly unfamiliar with both cygwin and msys2 and don't have either of them set up currently. If you give me a 3-4 days I'll have a bit more free time to set them up and I can respond back here with the results running under both alternatives!

@alex-courtis
Copy link
Member

This is a fantastic resource that will be invaluable in the future. I'd be eternally grateful for at least the cygwin one however don't feel pressured.

With all of these we can definitively map feature flags and remove the unnecessary checks, or at least make them lazy.

@jtledon
Copy link
Author

jtledon commented Oct 20, 2023

I've had pretty significant difficulties trying to get neovim installed within cygwin; the issues mostly revolve around some dependencies not being compatible with or available within cygwin. I was following the cygwin install directions and reading through some other discussions, but don't think I'll have the time to get it fully setup to run the has.lua file.

I haven't actually tried installing via msys2, though.

Please let me know if there's anything else I can do to help, or any other information that might be useful for you to have, especially pertaining to WSL2 installs.

@alex-courtis
Copy link
Member

Many thanks for the feature flags @jtledon , it was very enlightening: https://github.com/nvim-tree/nvim-tree.lua/wiki/Development#os-feature-flags

@alex-courtis
Copy link
Member

alex-courtis commented Oct 21, 2023

I've had pretty significant difficulties trying to get neovim installed within cygwin; the issues mostly revolve around some dependencies not being compatible with or available within cygwin. I was following the cygwin install directions and reading through some other discussions,

Wow... cygwin isn't looking good. Looking through issues I'm not seeing anything specific to cygwin or msys2 users.

msys2 support, which appears to be the same as cygwin, was added via #1295 Looking at the discussion in #1290 it seems we didn't really have any knowledge.

Options:

  1. Remove cygwin / msys support, although I'm not sure how we would actuall do that
  2. Put cygwin support behind a new option, default false
  3. Identify feature flags that can positively distinguish cygwin from wsl

I'll go with 2 for now to get things going.

@alex-courtis
Copy link
Member

alex-courtis commented Oct 21, 2023

@bstaint I'm reaching out to you as you are the only msys/cygwin user I know of.

We are having some performance issues with windows users scanning their paths for cygpath.exe

We need a definitive means of identifying cygwin without needing path scanning.

I would be most grateful if you could collect feature flags for msys2 and cygwin as per #2459 (comment)

Also... if you could explain the relationship/differences between msys and cygwin it would be most enlightening and allow us to properly support them in the future.

@alex-courtis
Copy link
Member

@jtledon I'd be most grateful if you tested the 2. fix:

cd /path/to/nvim-tree.lua
git pull
git checkout 2459-optional-cygwin-support

@jtledon
Copy link
Author

jtledon commented Oct 21, 2023

@alex-courtis The fix seems to work perfectly on my end! (using a dev load of that branch with lazy.nvim). All normal functionalty seems to work for me as well.

2459-nvim-tree-cygwin-off-by-default.mp4

Just for some additonal testing, I enabled the new git.cygwin_support flag within the 2459... branch and saw the exepected behavior: everything still worked fine with the plugin but the lag was reintroduced as one would assume.

Also, I just wanted to clarify from my previous statement, I'm by no means an expert on cygwin/msys2 and have never used either of them before. It's quite possible that all the install issues I was having could be easily resolved to get nvim working within them; I personally just wasn't having an easy time of it. That being said, I would be interested to hear more about them and the differences between them from someone who actually uses it.

@alex-courtis
Copy link
Member

alex-courtis commented Oct 21, 2023

saw the exepected behavior: everything still worked fine with the plugin but the lag was reintroduced as one would assume.

That's great, many thanks. All those conditionals are working as intended.

That being said, I would be interested to hear more about them and the differences between them from someone who actually uses it.

As would I. I last used cygwin the last time I used windows, 2006 or so.

alex-courtis added a commit that referenced this issue Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback bug Something isn't working OS Windows WSL specific to windows WSL
Projects
None yet
2 participants