Skip to content

Conversation

@hinell
Copy link

@hinell hinell commented Apr 2, 2025

nvim_lsp = function()
local results = {}
local diagnostics = vim.diagnostic.get()
for _, d in pairs(diagnostics) do
if diagnostic_is_enabled(d) then
if not results[d.bufnr] then results[d.bufnr] = {} end
table.insert(results[d.bufnr], d)
end
end
return results
end,

The above chunk of code gets constantly evaluated in a loop with diagnostics.get(options) fetching multiple times the same array with evergrowing number of diagnostics that get added by LSP over time.
The table diagnostics is evaluated by for _, d in pairs(diagnostics) loop multiple times though diagnostics remain the same. This results in a degraded performance.

Replicate the issue

I've discovered accidentally a massive drop in performance while configuring lua-language-server (LLS) for nvim plugin project.

Checkout a small bash script down below that automatically sets up a project that replicates the issue. It opens commands.lua file which gets over 2500+ diagnostics (to check this out, you can debug the above chunk of code).

Make sure that LLS is installed and configured for your nvim, and
you have the latest bufferline.nvim and the following config setup:

	config = {}
	config.options.diagnostics  = "nvim_lsp"
	config.options.diagnostics_update_on_event = true
	bufferline.setup(config)
REPLICATE.sh
#!/usr/bin/env -S bash 

pushd $(mktemp -d -p /tmp project-XXXXXXXXX)
test -d ./lua/test/ && echo "exists: ${_}" || mkdir -vp $_
test -s ./lua/test/commands.lua || {
cat <<EOL > ./lua/test/commands.lua
vim.api.nvim_del_user_command("string")
vim.api.nvim_create_user_command() 
---@type vim.api.keyset.create_user_command.command_args
local someVar
EOL
}


test -s .luarc.json || {
cat <<EOL > .luarc.json
{
	"\$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
	"runtime": {
		"version": "LuaJIT",
		"path": [
		]
	},
	"workspace": {
		"library": [
		"/usr/local/share/nvim/runtime/lua/vim/_meta.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/api.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/api_keysets.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/api_keysets_extra.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/base64.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/builtin.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/builtin_types.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/diff.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/lpeg.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/regex.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/vimfn.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/vvars.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_meta/vvars_extra.lua",
		"/usr/local/share/nvim/runtime/lua/vim/_options.lua"
		],
		"checkThirdParty": false,
		"userThirdParty": []
	},
	"diagnostics": {
		"globals": [
		"vim"
		],
		"disable": [
		"unused-local",
		"unused-vararg"
		]
	},
	"format.enable": false
}
EOL

}

echo "${0}: running editor ${EDITOR}"
${EDITOR:-nvim} -p ./lua/test/commands.lua /usr/local/share/nvim/runtime/lua/vim/_meta/api_keysets.lua

Workaround

Just disable diagnostics in

	config.options.diagnostics = false
	bufferline.setup(config)

Related

@hinell hinell force-pushed the diagnostics-limit branch from bb5481c to 14bbfe2 Compare April 4, 2025 12:26
@echoface
Copy link

echoface commented Oct 9, 2025

samilar issue when enable diagnostic, it cause 100% cpu usage and can't quit nvim normally(with gopls)

local opts = { silent = true }
vim.keymap.set("n", "<S-q>", "<cmd>Bdelete!<CR>", opts)

bufferline.setup {
  options = {
    close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
    right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
    offsets = {
      { filetype = "alpha", text = "", padding = 1 },
      { filetype = "neo-tree", text = "", padding = 1 },
      { filetype = "NvimTree", text = "", padding = 1 },
    },
    separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' },
    -- diagnostics = 'nvim_lsp', -- 100% cpu usage issue with gopls; and can't quit nvim(don't known why)
  },
}

@hinell
Copy link
Author

hinell commented Oct 9, 2025

@echoface Maintainer is busy in real life, seems like. Didn't answer reply since april... I got no time on hands either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants