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

Performance drawback #496

Closed
TyKonKet opened this issue Apr 6, 2021 · 32 comments · Fixed by #564
Closed

Performance drawback #496

TyKonKet opened this issue Apr 6, 2021 · 32 comments · Fixed by #564
Labels
bug Something isn't working

Comments

@TyKonKet
Copy link

TyKonKet commented Apr 6, 2021

With the latest versions I noticed a performance issue, I usually work with a large Lua workspace (more than 850 source files), before that issue the workspace diagnostics used to load up in less then 3 minutes or so.
Now with the latest version it takes never less then 2-3 hours to complete the diagnostic analysis.
I'm pretty sure it's an issue introduced with latest versions because when i rolled back the VSCode extension to version 1.20.1 the issue disappeared and diagnostics started back to load in 2-3 minutes.

Environment:

  • OS: Windows
  • Is WSL remote? No.
  • Client: VSCode
@sumneko
Copy link
Collaborator

sumneko commented Apr 6, 2021

Did you use generics in your project?

@TyKonKet
Copy link
Author

TyKonKet commented Apr 6, 2021

No, also the project isn't currently fully EmmyLua documented, most of files are still "plain lua".
One more info that may help you is that when the diagnostics runs fine, the project have zero errors and warnings.

@TyKonKet
Copy link
Author

TyKonKet commented Apr 6, 2021

Tested now with 1.20.3, but it's still very slow, seems that the issue exists both with 1.20.2 and 1.20.3

@mcb5637
Copy link

mcb5637 commented Apr 7, 2021

I noticed this too, and maybe this helps: When it hangs on diagnosis, there were a lot of notifications, that VS Code is currently running diagnosis on one file. Maybe the previous diagnosis doesnt get stopped when a new one starts?

@b0kker
Copy link

b0kker commented Apr 11, 2021

Can confirm what @mcb5637 said: https://i.imgur.com/rn5LfU4.mp4

@sumneko sumneko added the bug Something isn't working label Apr 12, 2021
@sumneko
Copy link
Collaborator

sumneko commented Apr 12, 2021

I noticed this too, and maybe this helps: When it hangs on diagnosis, there were a lot of notifications, that VS Code is currently running diagnosis on one file. Maybe the previous diagnosis doesnt get stopped when a new one starts?

It seems that the previous diagnosis task has fallen into an endless loop, so that it cannot handle the signal to stop the diagnosis.

@Nelvin
Copy link

Nelvin commented May 24, 2021

Same issue here, also while this happens, the language server uses a lot of memory - usually 3-5GB but sometimes even more than 10GB.

@WuJiayiSH
Copy link

looks like diagnosis takes much longer since 1.20.2 than 1.20.1

@WuJiayiSH
Copy link

might be caused by duplicated meta files, I have a copy of meta/3rd/cocos4.0 folder in my project, it doesn't happen when I remove it

@Nelvin
Copy link

Nelvin commented May 26, 2021

I don't have any meta folder in my project (it's a game using the Löve framework).

My guess at the moment is, that it might be caused by big files as one of my Lua files I do a lot of work in, is ~15k lines. Maybe it's just a kind of race condition in such situations ... but that's also just a guess.

@oblitum
Copy link

oblitum commented Jun 6, 2021

I just reported a similar experience here.

EDIT

I just figured out that when using lua-dev if I do:

local lua_settings = require('lua-dev').setup().settings.Lua
lua_settings.workspace.library = require('lua-dev.sumneko').library()
lua_settings.workspace.library['/usr/share/nvim/runtime'] = nil
vim.fn['coc#config']('Lua', lua_settings)

Everything becomes snappy. The key was to remove '/usr/share/nvim/runtime' from workspace.library. (cc @folke)

@akinsho
Copy link

akinsho commented Jun 8, 2021

FWIW I also observed the same behaviour and so disabled the runtime options, I still saw quite high CPU usage so I disabled the plugins as well. For more context for non-neovim users both these settings can add several hundred files to library for sumneko. Which I think it currently handles quite poorly i.e. very high CPU usage

@folke
Copy link
Contributor

folke commented Jun 14, 2021

@oblitum @akinsho I was still running 1.20.1 and with that version everything runs very smoothly.

Just upgraded and sumneko is totally unusable.

@folke
Copy link
Contributor

folke commented Jun 14, 2021

this version works

@folke
Copy link
Contributor

folke commented Jun 17, 2021

I'm debugging this issue right now and was able to bisect the performance degradation to this commit.

I'll see if I can make a fix.

@sumneko
Copy link
Collaborator

sumneko commented Jun 17, 2021

Thank you for the test, and sorry for the late reply.
I am currently refactoring the core code in the branch, but it may take some time.
If you are sure that the performance problem is caused by this commit, I can revert this comment on the master now.

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@sumneko I'll double-check and will let you know in a bit. Thanks!

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@sumneko I found the issue and created a PR. Performance is back to how it used to be now :)

@sumneko
Copy link
Collaborator

sumneko commented Jun 17, 2021

@folke It's awesome! Many thanks!

@folke
Copy link
Contributor

folke commented Jun 17, 2021

You're welcome and thank you for all the great work on the lua language server!

@oblitum
Copy link

oblitum commented Jun 17, 2021

Well, on my side it seems precisely the reverse has happened, even with my previous fix, things have become worse than before, it's consuming so much CPU that's affecting even while I'm typing this message o_O.

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@oblitum must be something else then on your end. I have another user of lua-dev that reported that new new server is very fast now. folke/neodev.nvim#14 (comment)

Are you sure you are using the latest version 1.21.3?

You also still should probably disable callsnippets, since that still causes a performance degradation. (haven't tested on the last release, since I have that disabled)

I made a small change to lua-dev as well, but not sure if that has any big impact on improving performance.

@oblitum
Copy link

oblitum commented Jun 17, 2021

Okay, it seems I've been actually affected by a change on the lua-dev.nvim plugin, not on the lua language server... Reverting it bring things back to normal.

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@oblitum are you sure about that? The new change to lua-dev removes some things from your package path and keeps /lua as part of the workspace directories, which means less work for lua-language-server. Can you try again? Maybe you were still running the old lua server in your test?

@oblitum
Copy link

oblitum commented Jun 17, 2021

Yes I'm sure, I upgraded everything before testing, then just reverted the commit from lua-dev.nvim to bring it to where it was before. It seems on my side I have not benefited the improvements on the server either, because I still need to use lua_settings.workspace.library['/usr/share/nvim/runtime'] = nil as I commented previously for things to be usable. So I'm precisely in the same state except for the lua-dev.nvim change.

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@oblitum no idea what's causing those issues on your end.

For me everything runs instantly with the runtime enabled.

@oblitum
Copy link

oblitum commented Jun 17, 2021

Before folke/neodev.nvim@6bf74db I get this:

:lua print(vim.inspect(require'lua-dev'.setup()))

{
  on_new_config = <function 1>,
  settings = {
    Lua = {
      awakened = {
        cat = true,
        <metatable> = <1>{
          __tostring = <function 2>
        }
      },
      diagnostics = {
        globals = { "vim" },
        <metatable> = <table 1>
      },
      runtime = {
        path = { "./?.lua", "/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/?.lua", "/usr/local/share/lua/5.1/?.lua", "/usr/local/share/lua/5.1/?/init.lua", "/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/?.lua", "/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/?/init.lua", "/home/francisco/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua", "/home/francisco/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua", "/home/francisco/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua", "/home/francisco/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua", "lua/?.lua", "lua/?/init.lua" },
        version = "LuaJIT",
        <metatable> = <table 1>
      },
      telemetry = {
        enable = false,
        <metatable> = <table 1>
      },
      workspace = {
        library = {},
        maxPreload = 2000,
        preloadFileSize = 150,
        <metatable> = <table 1>
      },
      <metatable> = <table 1>
    },
    <metatable> = <table 1>
  }
}

:lua print(vim.inspect(require'lua-dev.sumneko'.library()))

{
  ["/home/francisco/.local/share/nvim/site/pack/packer/opt/zen-mode.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/cheatsheet.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/hop.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lsp-colors.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim/types"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lualine.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-base16"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-tree.lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textsubjects"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-web-devicons"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/packer.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/plenary.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/popup.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope-coc.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/tmux-complete.vim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/todo-comments.nvim"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/vim-matchup"] = true,
  ["/usr/share/nvim/runtime"] = true
}

After folke/neodev.nvim@6bf74db I get this:

:lua print(vim.inspect(require'lua-dev'.setup()))

{
  settings = {
    Lua = {
      diagnostics = {
        globals = { "vim" },
        <metatable> = <1>{
          __tostring = <function 1>
        }
      },
      runtime = {
        path = { "lua/?.lua", "lua/?/init.lua" },
        version = "LuaJIT",
        <metatable> = <table 1>
      },
      telemetry = {
        enable = false,
        <metatable> = <table 1>
      },
      workspace = {
        library = {
          ["/home/francisco/.local/share/nvim/site/pack/packer/opt/zen-mode.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/cheatsheet.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/hop.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/lsp-colors.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim/types"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/lualine.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-base16/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-tree.lua/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textsubjects/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-web-devicons/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/packer.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/plenary.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/popup.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope-coc.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/tmux-complete.vim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/todo-comments.nvim/lua"] = true,
          ["/home/francisco/.local/share/nvim/site/pack/packer/start/vim-matchup/lua"] = true,
          ["/usr/share/nvim/runtime/lua"] = true,
          <metatable> = <table 1>
        },
        maxPreload = 2000,
        preloadFileSize = 150,
        <metatable> = <table 1>
      },
      <metatable> = <table 1>
    },
    <metatable> = <table 1>
  }
}

:lua print(vim.inspect(require'lua-dev.sumneko'.library()))

{
  ["/home/francisco/.local/share/nvim/site/pack/packer/opt/zen-mode.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/cheatsheet.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/hop.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lsp-colors.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lua-dev.nvim/types"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/lualine.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-base16/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-tree.lua/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textsubjects/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-treesitter/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/nvim-web-devicons/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/packer.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/plenary.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/popup.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope-coc.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/telescope.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/tmux-complete.vim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/todo-comments.nvim/lua"] = true,
  ["/home/francisco/.local/share/nvim/site/pack/packer/start/vim-matchup/lua"] = true,
  ["/usr/share/nvim/runtime/lua"] = true
}

So for my usage, I had to change this:

local lua_settings = require('lua-dev').setup().settings.Lua
lua_settings.workspace.library = require('lua-dev.sumneko').library()
lua_settings.workspace.library['/usr/share/nvim/runtime'] = nil
vim.fn['coc#config']('Lua', lua_settings)

to this:

local lua_settings = require('lua-dev').setup().settings.Lua
lua_settings.workspace.library['/usr/share/nvim/runtime/lua'] = nil
vim.fn['coc#config']('Lua', lua_settings)

Note that I don't need to call require('lua-dev.sumneko').library() as it's already embedded in the .setup() call.

But the critical part for me is that now I have to exclude '/usr/share/nvim/runtime/lua', not '/usr/share/nvim/runtime' as before.

So, in the end, after this fix, speed is back to normal (still having to exclude something from library).

@oblitum
Copy link

oblitum commented Jun 17, 2021

@folke despite excluding '/usr/share/nvim/runtime/lua', I still get completion and docs for the stuff in there because you already provide compiled "EmmyLua library for the nvim lua API" embedded to lua-dev.nvim right? If that's the case, why still have /usr/share/nvim/runtime/lua listed in workspace.library, as it would solely provide a poorer duplicate? (And which by removing so, I fix my problems)

@oblitum
Copy link

oblitum commented Jun 17, 2021

Oh, sorry regarding poor report on my own version check. Even though I got an update prompt from coc-lua, for which I confirmed, coc-lua-binaries 1.21.3 is still on pre-release, so I may have not picked it yet (I'm still confused on that, will have to check it later).

@oblitum
Copy link

oblitum commented Jun 17, 2021

Okay, I updated the binaries manually (coc-lua binaries update process is broken) and indeed, I don't need to exclude runtime anymore! Sorry for the confusion. Also, it's indeed much faster than before, even when having runtime excluded.

@folke
Copy link
Contributor

folke commented Jun 17, 2021

@oblitum glad you got it working!

If you're not including the runtime, then you won't get proper docs for lua functions in the runtime. Things like what I include here

So lsp, treesitter, vim shared, ...

Those functions are not included in the emmy annotations directly. They are even excluded on purpose, since lua-language-server can be smarter about inferring types for return values, dictionaries, etc

@oblitum
Copy link

oblitum commented Jun 17, 2021

thx @folke!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants