Skip to content

Instantly share code, notes, and snippets.

@kylo252
Created November 25, 2021 09:58
Show Gist options
  • Save kylo252/8ed50f2d69c069d066bd6ef69c9ee182 to your computer and use it in GitHub Desktop.
Save kylo252/8ed50f2d69c069d066bd6ef69c9ee182 to your computer and use it in GitHub Desktop.
lspconfig benchmarks

Description

Benchmark for setting up all/multiple servers at startup

Results

  • Baseline
hyperfine "./nv-bench" -r 100 --cleanup "rm -f $HOME/.cache/nvim/{lsp.log,log}" --export-markdown results-baseline.md --command-name 'baseline'
Command Mean [ms] Min [ms] Max [ms] Relative
baseline 39.2 ± 6.9 30.3 61.5 1.00
  • Modularized
hyperfine "./nv-bench" -r 100 --cleanup "rm -f $HOME/.cache/nvim/{lsp.log,log}" --export-markdown results-1479.md --command-name 'modular-configs-1479'
Command Mean [ms] Min [ms] Max [ms] Relative
modular-configs-1479 39.3 ± 5.4 30.7 63.7 1.00
local on_windows = vim.loop.os_uname().version:match("Windows")
local function join_paths(...)
local path_sep = on_windows and "\\" or "/"
local result = table.concat({ ... }, path_sep)
return result
end
vim.cmd([[set runtimepath=$VIMRUNTIME]])
local temp_dir
if on_windows then
temp_dir = vim.loop.os_getenv("TEMP")
else
temp_dir = "/tmp"
end
vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))
local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
"neovim/nvim-lspconfig",
-- "nvim-lua/plenary.nvim" -- profiler wasn't really useful here
},
config = {
package_root = package_root,
compile_path = compile_path,
},
})
end
_G.load_config = function()
-- require('plenary.profile').start("lspconfig_profile.log")
vim.lsp.set_log_level("ERROR")
if vim.fn.has("nvim-0.5.1") == 1 then
require("vim.lsp.log").set_format_func(vim.inspect)
end
local nvim_lsp = require("lspconfig")
local on_attach = function(_, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings.
local opts = { noremap = true, silent = true }
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
buf_set_keymap("n", "<space>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
end
-- Enable the following language servers
local test_servers = {
"bashls",
"beancount",
"bicep",
"clangd",
"clojure_lsp",
"cmake",
"crystalline",
"cssls",
"dartls", --- adds ~120ms
"dockerls",
"elixirls",
"elmls",
"erlangls",
"fortls",
"gdscript",
"gopls",
"graphql",
"hls",
"html",
"intelephense",
-- "jdtls", --- adds ~20ms
"jsonls",
"julials",
"kotlin_language_server",
"metals",
"omnisharp",
"powershell_es",
"puppet",
"pyright",
"r_language_server",
-- "rnix", --- causing some problems on the new config for some reason
"rust_analyzer",
"serve_d",
"solang",
"solargraph",
"sourcekit",
"sqls",
"sumneko_lua",
"svelte",
"tailwindcss",
"terraformls",
"texlab",
"tsserver",
"vimls",
"vuels",
"yamlls",
"zls",
}
for _, lsp in ipairs(test_servers) do
local success, _ = pcall(function()
nvim_lsp[lsp].setup({
on_attach = on_attach,
})
end)
if not success then
print("error calling: " .. lsp)
end
end
-- require'plenary.profile'.stop()
--
-- print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
end
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once lua load_config()]])
else
load_plugins()
require("packer").sync()
end
_G.load_config()
vim.cmd([[qall]])
#!/usr/bin/env bash
INIT_LUA="${INIT_LUA:-$PWD/minimal_init.lua}"
export VIMRUNTIME="$HOME/.local/share/neovim/runtime"
nvim --headless -u "$INIT_LUA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment