Neovim lags onsave is very slow and I don't know how to fix it

I have a weird kind of problem where every time I save my file using :w or zz neovim as a whole lags for sometime. This most of the times happens when I try to save large files which are about 2k+ lines. It happens mostly with TypeScript, Golang and Zig. I tried to search for this issue but couldn’t find. One thing I know is that when I do nvim -u NONE its of course very fast then. No problems. So, the problem arises from one of my plugins.

Now, I am not sure how to fix the problem. That’s the thing. Can someone guide me as to how to proceed and debug?

Here is my plugin list:

        use {"wbthomason/packer.nvim", opt = true}
        use {"kyazdani42/nvim-web-devicons"}
        use {"kyazdani42/nvim-tree.lua"}
        use {"nvim-lua/plenary.nvim"}
        use {"lewis6991/gitsigns.nvim"}
        use {"glepnir/galaxyline.nvim"}
        use {"akinsho/nvim-bufferline.lua"}
        use {"norcalli/snippets.nvim"}
        use {"nvim-treesitter/nvim-treesitter"}
        use {'nvim-treesitter/playground'}
        use {"chriskempson/base16-vim"}
        use {"norcalli/nvim-colorizer.lua"}
        use {'Yggdroot/indentLine'}
        use {"ryanoasis/vim-devicons"}
        use {"sbdchd/neoformat"}
        use {"neovim/nvim-lspconfig"}
        use {"hrsh7th/nvim-compe"}
        use {"windwp/nvim-autopairs"}
        use {"alvan/vim-closetag"}
        use {"tweekmonster/startuptime.vim"}
        use {"onsails/lspkind-nvim"}
        use {"nvim-telescope/telescope.nvim"}
        use {"nvim-telescope/telescope-media-files.nvim"}
        use {"nvim-lua/popup.nvim"}
        use {"b3nj5m1n/kommentary"}
        use {"zah/nim.vim"}
        use { "kdheepak/lazygit.nvim" }
        use {"akinsho/nvim-toggleterm.lua"}
        use {'iamcco/markdown-preview.nvim', run = 'cd app && pnpm i', cmd = 'MarkdownPreview'}

This effectively is asking the community to binary search your plugin list. I’d recommend doing it yourself and reporting back. There’s a small possibility it’s lsp related, but I have no idea what BufClose autocommands you might be doing.

So, basically I disable one plugin and then try the same thing. Could try that. I will surely report back on the same.

BTW what is the autocmd for saving a file? It could help me debug better.

My intention is not to make the community go through the same. Just in case someone did have the same problem and solved the issue might be of help. Throwing the question with hope TBF.

Writing my solution to the problem.

Use set shell=/bin/bash instead of fish. This is because fish is slightly slower than bash. This is specially true in case of the plugins that use shell commands. Even startup times are faster when bash is used.

In my case I have a few fish functions and path that are setup to work on startup, so startup times for fish in my case is fast “enough”. bash is blindingly fast though.

The above is the relevant issue that might help.

I was suggesting a binary search, so in the future disable half your plugins, see if the issue is gone, then cut the current list in half again and recurse

3 Likes