mathworks / MATLAB-language-server

MIT License
85 stars 9 forks source link

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

Open sh-cau opened 2 months ago

sh-cau commented 2 months ago

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



**Additional context**
--
dklilley commented 2 months ago

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?

sh-cau commented 2 months ago

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.