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

High memory usage in Nvim with mason, mason-lspconfig, nvim-lspconfig #48

Open
sh-cau opened this issue Sep 3, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@sh-cau
Copy link

sh-cau commented Sep 3, 2024

Describe the bug
When I open any buffer that is a Matlab file, the LSP server starts and has ~2GB of memory on each tmux window. Since I use many windows for different repos simultaneously in one tmux session, my RAM tends to overflow if I am not careful.
Also the language server process does not end when I just close the terminal containing the tmux session. If I close the windows individually, the corresponding processes also stop.

To Reproduce
Steps to reproduce the behavior:

  1. Start tmux
  2. Open nvim and edit a matlab file
  3. Open a new window Ctrl-b + c, go to that window, repeat 1.+2.
  4. Open btop or top and filter for matlab process.

Expected behavior
I would expect the LSP to be more lightweight and not use up so much RAM?! According to the screenshot, an entire MATLAB instance is started to run the language server?!

Screenshots

btop screenshot

Useful Information

  • OS Version: Ubuntu 20.04 with nvim v0.10.1
  • Language Server Client: matlab_ls in combination with mason, mason-lspconfig and nvim-lspconfig
  • Client Version: commit hash eb1aab2
  • Node version: v18.0.0
  • (relevant) Lazy Nvim LSP config:
return {
    {
        'williamboman/mason.nvim',
        config = function()
            require('mason').setup({})
        end
    },
    {
        'williamboman/mason-lspconfig.nvim', -- bridges Mason with nvim-lspconfig
        config = function()
            require('mason-lspconfig').setup({
                ensure_installed = {
                    'matlab_ls',
                    'bashls',
                    'lua_ls',
                    'clangd',
                    'ltex',
                    'marksman',
                    'gitlab_ci_ls',
                    'yamlls',
                },
            })
        end
    },
    {
        'neovim/nvim-lspconfig',
        dependencies = { 'hrsh7th/cmp-nvim-lsp'},
        config = function()
            local lspconfig = require('lspconfig')
            local capabilities = require('cmp_nvim_lsp').default_capabilities()
            lspconfig.matlab_ls.setup({
                capabilities = capabilities,
                filetypes = { "matlab" },
                settings = {
                    matlab = {
                        installPath = "/home/sh/programs/MATLAB/R2023a/", -- also tried not setting this
                        telemetry = false, 
                    },
                },
                single_file_support = true, -- also tried false 
            })
            lspconfig.bashls.setup({
                capabilities = capabilities,
                filetypes = { "sh", "zsh", "bash" },
                settings = {
                    bashls = {
                        lint = {
                            enable = true,
                            diagnostics = true,
                            use = { "shellcheck" },
                        },
                    },
                },
            })
            lspconfig.lua_ls.setup({
                capabilities = capabilities,
                settings = {
                    Lua = {
                        diagnostics = {
                            globals = { 'vim' } -- avoids warnings that vim is not found
                        }
                    }
                }
            })
            local function quickfix() vim.lsp.buf.code_action({ apply = true }) end
            local map = require('utils').map
            vim.api.nvim_create_autocmd('LspAttach', {
                callback = function(args)
                    -- mappings
                end
            })
        end
    },
}

Additional context

@sh-cau sh-cau added the bug Something isn't working label Sep 3, 2024
@dklilley
Copy link
Member

dklilley commented Sep 5, 2024

My suspicion is that, as with VS Code, Nvim does not share an instance of the language server between separate Nvim windows. Because of this, each window is instantiating a new instance of the language server, which is then starting its own MATLAB process.

We are aware of this higher-than-expected memory cost for running the language server, and are investigating options for reducing this in the future.

As we continue to look into this, it would be helpful to understand more about your workflow so we can ensure it is captured in our future solution. Can you give some more context about why you are using multiple Nvim windows instead of just one? Is this a Nvim limitation (only one repository per window), or is it more efficient for you?

@dklilley dklilley added enhancement New feature or request and removed bug Something isn't working labels Sep 5, 2024
@sh-cau
Copy link
Author

sh-cau commented Sep 5, 2024

I suspected as much. Yes, indeed, I am working with multiple (MATLAB) repos and each repo has its own tmux window but mainly for organization purposes, i.e., to keep the buffer list local to that particular repo, e.g., when I use :bufdo %s/old/new/g I don't mess up other repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants