High Memory Usage of sourcekit-lsp in VSCode on Ubuntu 20.04 (original) (raw)

October 22, 2024, 1:14am 1

I am experiencing an issue where after some time, sourcekit-lsp consumes almost all my memory when programming in VSCode on Ubuntu 20.04. I have tried both Swift 5.10 and Swift 6, but the problem persists. This high memory usage is causing significant inconvenience. Does anyone have suggestions on why this might be happening or how to resolve it?

image

Genaro-Chris (Genaro Christian) October 22, 2024, 9:48am 2

Yeah, I noticed it since swift 5.5 馃う

same problem on Ubuntu 24.04. oftentimes, sourcekit-lsp is by far the biggest memory user on my system:

image

ahoppen (Alex Hoppen) October 23, 2024, 1:06am 4

We have an issue tracking the problem (High memory usage 路 Issue #1541 路 swiftlang/sourcekit-lsp 路 GitHub) but haven鈥檛 been able to gain any insight into what鈥檚 using the memory yet.

I am not super familiar with memory debugging on Linux, in case somebody has a way to capture what objects are using the memory (something similar to a memgraph on macOS), that would be tremendously helpful.

martinlau (Martin Lau)

October 23, 2024, 3:23am 5

I'm not sure if heaptrack meets your requirements. After a preliminary analysis using heaptrack, I found that SourceKit::WorkQueue::DispatchData::callAndDelete() had the highest memory consumption. However, as I鈥檓 not very familiar with this tool, I cannot provide accurate results.

ahoppen (Alex Hoppen) October 23, 2024, 6:16pm 6

Thanks @martinlau, that鈥檚 quite helpful. I will try and find the time to look at it and update the issue I referenced above once I have news.

ahoppen (Alex Hoppen) October 30, 2024, 9:02pm 7

Thanks for the tip with heaptrack, it enabled me to track the issue down to Fix a memory leak in `DispatchData.withUnsafeBytes` by ahoppen 路 Pull Request #850 路 swiftlang/swift-corelibs-libdispatch 路 GitHub.

One question: Did you run heaptrack on a toolchain you downloaded from swift.org or did you build a toolchain yourself? I wasn鈥檛 able to get any symbol information out of heaptrack without debug information for the binaries that I was testing. Wondering if there鈥檚 a trick.

martinlau (Martin Lau) October 31, 2024, 2:03am 8

Glad to see the progress! For heaptrack to read symbol information, it might be necessary to build the toolchain yourself for testing. When I ran heaptrack on the toolchain downloaded from swift.org, I couldn鈥檛 see symbol information鈥攐nly a general memory trace.

ahoppen (Alex Hoppen) October 31, 2024, 3:24am 9

OK, I figured that you could see symbol information because you pointed to SourceKit::WorkQueue::DispatchData::callAndDelete().

martinlau (Martin Lau)

November 1, 2024, 7:18am 10

Hi @ahoppen,

Based on my recent heaptrack memory analysis, I haven't found high memory usage related to the symbol SourceKit::WorkQueue::DispatchData::callAndDelete() (currently using Swift version 6.0.2). Instead, the memory consumption appears to be primarily focused on _dispatch_operation_perform. This might be related to Fix a memory leak in DispatchData.withUnsafeBytes #850.
If needed, I can provide the gz files from my last two analyses.

1730446644559

ahoppen (Alex Hoppen) November 1, 2024, 7:27pm 11