elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
417 stars 31 forks source link

Getting very slow neovim startup time after using elixir.nvim #59

Closed NJichev closed 1 year ago

NJichev commented 1 year ago

Adding elixir.nvim and then installing elixirls once it asked me to made my config load take 2s+. i.e doing nvim foo.ex --startuptime output does this:

times in msec
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.007  000.007: --- NVIM STARTING ---
...(truncated)
1989.936  1916.747: opening buffers.  <---- line in question
2009.648  019.712: BufEnter autocommands
2009.650  000.003: editing files in windows
2009.777  000.126: VimEnter autocommands
2009.801  000.024: UIEnter autocommands
2009.803  000.002: before starting main loop
2119.209  109.407: first screen update
2119.212  000.002: --- NVIM STARTED ---

Now removing elixir.nvim from my config:

...(truncated)
190.560  122.877: opening buffers
190.614  000.054: BufEnter autocommands
190.616  000.002: editing files in windows
190.702  000.086: VimEnter autocommands
190.739  000.037: UIEnter autocommands
190.959  000.100  000.100: sourcing /Users/njichev/.asdf/installs/neovim/0.8.2/share/nvim/runtime/autoload/provider/clipboard.vim
190.964  000.126: before starting main loop
283.900  092.936: first screen update
283.904  000.003: --- NVIM STARTED ---

Note that Lazy's profiling says that elixir.nvim loads quite fast:

    ●   elixir 7.26ms
      ➜   elixir.nvim 5.96ms
        ★   plenary.nvim 0.35ms
          ‒   plenary.nvim/plugin/plenary.vim 0.06ms

I tried switching between neovim versions 0.8.2, 0.8.3 and stable in asdf and I get the same results on each.

I used the default config for the lazy.nvim plugin manager in the readme: https://github.com/mhanberg/elixir.nvim#lazynvim So what am I doing wrong, I recently started moving my vimscript config to lua so I might be perfectly messing something up 😅

Here’s my nvim config

Edit: I also tried opening a file in a project, i.e nvim lib/page.ex for example and get the same behaviour if that's any information.

Edit2: I am using the following elixir/erlang versions: 1.14.3-otp-25/25.3 on a macbook with M1 Pro

NJichev commented 1 year ago

Actually one of my tries of opening an elixir file got this on the stderr after closing nvim:

Error executing vim.schedule lua callback: ...vim/lazy/elixir.nvim/lua/elixir/language_server/init.lua:302: Failed to insert line
stack traceback:
    [C]: in function 'nvim_buf_set_lines'
    ...vim/lazy/elixir.nvim/lua/elixir/language_server/init.lua:302: in function 'handler'
    ...installs/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1049: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
mhanberg commented 1 year ago

Actually one of my tries of opening an elixir file got this on the stderr after closing nvim:

Error executing vim.schedule lua callback: ...vim/lazy/elixir.nvim/lua/elixir/language_server/init.lua:302: Failed to insert line
stack traceback:
  [C]: in function 'nvim_buf_set_lines'
  ...vim/lazy/elixir.nvim/lua/elixir/language_server/init.lua:302: in function 'handler'
  ...installs/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1049: in function ''
  vim/_editor.lua: in function <vim/_editor.lua:0>

You can ignore this.

mhanberg commented 1 year ago

This is very strange.

What does :Lazy profile say for you startup time in general?

NJichev commented 1 year ago

Just opening nvim:

  Startuptime: 53.86ms

  Based on the actual CPU time of the Neovim process till UIEnter.
  This is more accurate than `nvim --startuptime`.
    LazyStart 36.73ms
    LazyDone  46.57ms (+9.84ms)
    UIEnter   53.86ms (+7.29ms)

Full output

Opening a random file ending with .ex nvim foo.ex:

  Startuptime: 63.96ms

  Based on the actual CPU time of the Neovim process till UIEnter.
  This is more accurate than `nvim --startuptime`.
    LazyStart 37.98ms
    LazyDone  48.26ms (+10.28ms)
    UIEnter   63.96ms (+15.7ms)

Full output

mhanberg commented 1 year ago

I had another report from someone who uses LunarVim that after switching to elixir-tools.nvim, opening an elixir file using telescope took 5+ seconds

i still can't reproduce.

NJichev commented 1 year ago

I have switched for now to using plain elixir-ls by compiling it manually along with Mason nvim, if you have any ideas for me to debug I can try them out. It's certainly weird what's happening, it could be something completely because of something local or some weird interaction between lazy.nvim and the plugin?

I will try if I can provide a minimized version of my dotfiles and see if it's still happening

mhanberg commented 1 year ago

A minimal reproduction would be wonderful, if possible.

mhanberg commented 1 year ago

if your dotfiles are hosted somewhere, I should be able to clone them and using the (new with 0.9) NVIM_APPNAME to start up a neovim instance using your dotfiles (without affecting my own or conflicting with my own plugins)

NJichev commented 1 year ago

Yeah, you can check them out here: https://github.com/NJichev/dotfiles/tree/master/config/nvim

mhanberg commented 1 year ago

I think I was able to reproduce this with your config.

I think my own setup does the same, but my mental grasp of what 2 seconds feels like was way off haha.

I will investigate what is taking so long once the buffer is entered.

mhanberg commented 1 year ago

oh duh... it's calling elixir --version to get your current projects elixir and erlang version. that takes about 400ms on my computer.

I'll try to think of a better method for this.

mhanberg commented 1 year ago

thanks for the patience @NJichev!