-
Notifications
You must be signed in to change notification settings - Fork 411
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
high ram and cpu usage with tailwindcss #1009
Comments
It is not nvim-cmp issue. |
Thanks for the answer! I mean ram usage big not in LSP process, but in nvim itself, like 700 mb and higher with nvim-cmp. If i use it with coc-nvim - all is fine, memory is low. Maybe i something don't understand.
|
If so, it should be reported in nvim-lspconfig instead. |
I think there is some leak in nvim-cmp itself or cmp-nvim-lsp. Configuration of tailwindcss in nvim-lspconfig is correct. With coc-nvim tailwindcss works fine. Ram usage 1.3g with tailwindcss - just an example: Screencast.2022-06-26.09.22.07.mp4 |
Maybe some problems in LSP implementaion of neovim? |
|
I can also reproduce this issue and I've posted about it here aswell: neovim/neovim#19118 (comment) When disabling nvim-cmp I have no issues at all. Let me add: I've tested it with omnifunc (vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')) - no laggs. Memory below 250 mb. |
@username664 Can you reopen this? Or did you find a solution? People still seem to be having a problem with this including myself. |
It is closed. Because it is not nvim-cmp problem. |
@Shougo how is this not a nvim-cmp problem? Please read this neovim/neovim#19118 (comment) I can only reproduce it with nvim-cmp :( |
Please test other LSP completion plugins(It must use |
Hm... I will try it with ddc.vim. Please create the minimal init.vim and the reproduce-able source code. |
It is really nvim-cmp problem? |
I didnt test ddc.vim, only coq_nvim, and no problems there. If you still need reproducable repos, let me know. |
I don't reproduce it with ddc.vim. |
I have tested nvim-cmp with tailwindcss. Note: The lags is not found in ddc.vim. set rtp+=~/src/nvim-cmp
set rtp+=~/src/cmp-buffer
set rtp+=~/src/cmp-nvim-lsp
set rtp+=~/src/vim-vsnip
set rtp+=~/src/cmp-vsnip
set rtp+=~/src/nvim-lspconfig
set rtp+=~/src/cmp-cmdline
set title
set titlestring="%F %r"
lua <<EOF
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
print(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<tab>'] = cmp.mapping(cmp.mapping.confirm({ select = true }), { 'i', 's', 'c' }),
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
},
completion = {
completeopt = 'menu,menuone,noselect'
}
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'cmdline' }
}
})
EOF
lua << EOF
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
--require'lspconfig'.sumneko_lua.setup{}
--require'lspconfig'.cssls.setup{}
--require'lspconfig'.pylsp.setup{}
require'lspconfig'.tailwindcss.setup{}
require'lspconfig'.gopls.setup{
capabilities = capabilities,
init_options = {
usePlaceholders = true,
},
}
EOF
runtime! after/plugin/*.lua |
|
It seems nvim-cmp problem instead of @hrsh7th Can you test it? |
@Shougo thanks for your effort man, j just logged in to create the repo for you to see you are done already. Cheers, hope we find a quick fix |
I'd investigate this.
|
If you want to limit the allocation of memory space as much as possible, you can run collectgarbage('collect') on the InsertLeave event. |
I'd pushed the performance improvements in e1f3177 |
No need to backport anything. You can apply yioneko's changes as a patch to the master branch without any merge conflicts (for now). Though I do hope that hrsh7th can look up his commit and maybe hopefully improve on that whenever he gets time. |
This is probably slightly tangential, but how can we profile runtime performance of a plugin? Like this plugin: https://github.com/tweekmonster/startuptime.vim, but not just for startup time. Because I feel like trying to optimize without knowing what is taking time is pretty difficult. |
Nvm I found https://github.com/nvim-lua/plenary.nvim#plenaryprofile. Sorry for the noise. |
This improves it for me in my particular setup. Thank you! |
Just jumping in on this issue to say that using yioneko's fork has completely fixed my stuttering issues! |
I've applied the mentioned patch (https://github.com/yioneko/nvim-cmp/commit/ca812e4c0d677f4cebd94bbe7a875412dc8e90d2.patch). It does not really help, it still is stuttering for me. |
@hrsh7th I just did some testing and the extreme memory usage is caused by this line Line 126 in d153771
I don't really understand what that code does that calculates In the case of tailwind, on my config, I get 11000 completion items per completion. If I'm in a tsx file, inside a If I remove the line that adds the entries to the cache, memory usage stays stable. If I understand the code correctly, it's probably best to remove the whole |
If the
If we remove the
I can provide the option for this. |
I'm working on a fix. It's not needed to process all the items since by default only 200 are returned? |
I was reviewing the code and noticed that nvim-cmp was no longer returning correct results. Originally, items should be cut after sorting by score. But already nvim-cmp is doing pre-filtering. Also, be aware that your fix raises CPU load and reduces memory load. google translated |
|
Yes. Your fix does not affect the sorting and filtering results. But I notice your fix fixes |
I think that understanding and incorporating @yioneko's solution will be the fundamental solution (introducing a time budget to the filtering process) But I have a lot of tasks, so I can't investigate right away. It's also possible that yioneko's solution won't help either. |
@yioneko solution doesn't fix the memory issue. But I do agree that async processing will also be needed. My solution does fix the memory issue and by printing the amount of processed entries before and after my changes, on average, less items are processed for filtering, so it does make it faster than before and does use less CPU. Did you find the opposite? |
First, I think
Your fix seems to be the following to me.
|
TBH, I'm confusing with this problem.
So contrary to my opinion, folke's solution may work. I'll try native omnifunc with tailwindcss language server. |
This comment was marked as resolved.
This comment was marked as resolved.
@hrsh7th turns out that I just fixed that as well, so that calculating the filtered items will only be done when the context changes. This makes a really big difference. Stuttering in Tailwind is pretty much non-existent now for me. |
Very good news! The |
In my case 100% @yioneko's solution solved my stutter issue completely. I never looked at RAM usage since I have so much RAM to begin with, but the stutter was very noticeable. With @yioneko's the stutter went away.
From the little I have read of the conversation, @folke's solution is about avoiding unnecessary work by aborting early once internal I could well believe that @folke's solution would help with both excessive RAM and stutter. Hmm, as I am typing this, maybe it is better that I just try @folke's PR and report back rather than speak theoretically. To-be-continued. |
IMO, the de-duplication of get_entries will fix most of the problems. folke thanks for finding this! |
My results:
Both @folke's (smartly avoid unnecessary work) and @yioneko's (async interrupt) patches would together appear to be the ultimate solution. |
solved the issue: #1574 |
Thanks for a quick turn around on this one! Much appreciated! |
For anyone that wants to try, there's a new PR that makes cmp async #1583 |
FAQ
Announcement
Minimal reproducible full config
Description
Neovim 0.7.0. Linux debian.
While using tailwindcss in class(className) - ram is out of control and cpu is high.
Steps to reproduce
Just install via LspInstall tailwindcss and start using it. In React or something.
Expected behavior
Low ram and cpu, without lags.
Actual behavior
Lags and ram usage big.
Additional context
No response
The text was updated successfully, but these errors were encountered: