swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.2k stars 264 forks source link

High memory usage #1541

Open ebak opened 3 days ago

ebak commented 3 days ago

Description

I have recently tried out the stable tool-chain (installed with swiftly on Manjaro Linux) with VSCode and its Swift plugin. The memory usage of sourcekit-lsp easily freezes out the machine.

The machine has 16 CPU threads (8 core with 2 HW threads), but only 8GB RAM. As I suspect the number of sourcekit-lsp threads scales up based on the number of CPU threads.

Is it possible to explicitly limit the sourcekit-lsp threads? (Linux allows to turn off some cores, but that is not too convenient.)

Or would it be possible to also consider available RAM too when spawning sourcekit-lsp threads? E.g. for 8GB of RAM only spawn 3 threads, even if the machine have 256 CPUs.

ahoppen commented 3 days ago

Synced to Apple’s issue tracker as rdar://130844901

ahoppen commented 2 days ago

Hey @ebak,

A couple of questions:

ebak commented 1 day ago

Hi,

Now I don't have possibility to try it on the machine with 8 CPUs, maybe next week.

How much memory does sourcekit-lsp use on your machine? I would be expecting something <500MB on start up, fairly independent of your CPU core count.

I attach screenshots of htop output, as I see at startup it only consumes 2.8% (I don't know what htop means about this percentage.)

Screenshot from 2024-07-02 10-57-56

Does the memory usage of SourceKit-LSP grow over time or does it go up immediately after launching

Grows over time. As I see build and source browsing is required for it.

Screenshot from 2024-07-02 11-49-07

Does this also reproduce with a Swift 6 toolchain. We have made significant changes to SourceKit-LSP between 5.10 and 6.0, so the issue might already be fixed.

Not yet tried out, maybe I'll do when I have possibility to play it around with the system with 8 CPUs.

Does the memory usage go up on every project that you open or only on specific ones? If so, would you be able to share the project?

Recently I was working with this project (QtTest): QtTest.zip

ebak commented 1 day ago

Just by editing the same code, the memory usage quickly goes up to 45% (3.6GB maybe):

Screenshot from 2024-07-02 15-31-16

Maybe unrelated but VSCode usually forgets about the dependent packages:

VSCode-Screenshot from 2024-07-02 15-36-06

The dependencies (Qlift, Math) are sometimes shown up there, sometimes not.

Sad the 8GB RAM is hardly enough for IDE assisted development. In my case the opened apps almost use up all free memory (Gnome, 2 terminals, 2 file managers, a light weight editor (gedit), an ebook reader for the Swift book, VSCode with Swift instrumentation). Opening up a Firefox with 1-2 tabs would easily freeze out the system.