You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Does the memory usage of SourceKit-LSP grow over time or does it go up immediately after launching
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.
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?
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.)
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.
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
Just by editing the same code, the memory usage quickly goes up to 45% (3.6GB maybe):
Maybe unrelated but VSCode usually forgets about the dependent packages:
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.
Thanks! With the 6.0 or the 5.10 toolchain? Maybe if this issue doesn't exist in 6.0, this issue could be closed and wait for 6.0 to get stable. (Currently I cannot test.)
Oh, that’s interesting that you’re also seeing excessive memory usage on macOS. I haven't seen that before.
Could you try reproducing the problem, run leaks --outputGraph=/tmp sourcekit-lsp and then share the .memgraph file that is being generated the command? I’m hoping that will show us where the memory allocations are from.
I think it would be valuable to see the graph when SourceKit-LSP is at ~2GB. That’s already more than it should take and should contain the culprit who’s using the memory.
@m-buczek it's interesting that you needed SIP to be disabled, for me it worked without disabling it.
btw @ahoppen can you confirm to us if the changes to sourcekit-lsp were merged to Xcode[or swift which later merged to Xcode]
@terraputix That seems surprising to me, that would imply we're leaking entire ASTContexts. Do you have a project you can share that reproduces the issue?
i can confirm that something is leaking again, on Mac OS, sourcekit-lsp took up 48GB of ram.
unfortunately, i wasn't able to get a mem dump because the whole system freezed
The macOS and Linux leak are probably unrelated because the Linux leak seems to be coming from sourcekitd. macOS runs sourcekitd out-of-process, so the leak here must be coming from a leak inside SourceKit-LSP itself.
@iMostfa and @terraputix Could you file separate issues for the leaks you are seeing and include the following information?
Which version of SourceKit-LSP are you using?
Is this issue happening for one particular project / on one specific interaction or always? If it is one project, can you share it?
Do you have a rough rate at which it is leaking? Eg. does it take a minute to leak 1 GB, 5 minutes, one hour, etc.
I want to mention I've also been experiencing a lot of leaks for a long time. I was blaming it on Cursor and simply reopen Cursor to fix, but lately noticed It's actually not Cursor. I'll be trying to catch the leak and see if it matches any of the cases reported above.
Just a report: I haven't noticed something that I could call a "leak", recently, on macOS.
The memory usage is still somewhat high (~6-12GB in a M1 16GB machine - swap is definitely saving me) but it doesn't just go up indefinitely.
Activity
ahoppen commentedon Jun 30, 2024
Synced to Apple’s issue tracker as rdar://130844901
ahoppen commentedon Jul 2, 2024
Hey @ebak,
A couple of questions:
ebak commentedon Jul 2, 2024
Hi,
Now I don't have possibility to try it on the machine with 8 CPUs, maybe next week.
I attach screenshots of
htopoutput, as I see at startup it only consumes 2.8% (I don't know whathtopmeans about this percentage.)Grows over time. As I see build and source browsing is required for it.
Not yet tried out, maybe I'll do when I have possibility to play it around with the system with 8 CPUs.
Recently I was working with this project (
QtTest):QtTest.zip
ebak commentedon Jul 2, 2024
Just by editing the same code, the memory usage quickly goes up to 45% (3.6GB maybe):
Maybe unrelated but
VSCodeusually forgets about the dependent packages: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.
ahoppen commentedon Jul 4, 2024
I have been able to reproduce the memory growth by working on the SourceKit-LSP codebase in VS Code on Ubuntu 22.04.
ebak commentedon Jul 4, 2024
Thanks! With the 6.0 or the 5.10 toolchain? Maybe if this issue doesn't exist in 6.0, this issue could be closed and wait for 6.0 to get stable. (Currently I cannot test.)
ahoppen commentedon Jul 15, 2024
I saw the memory issue with a 6.0 toolchain.
[DO NOT MERGE] Use default cache on macOS
iMostfa commentedon Sep 28, 2024
i think that this issue is happening more after updating to Xcode 16.
it keeps growing until the whole device get freezed.
iMostfa commentedon Sep 30, 2024
i downloaded Xcode 15, copied the sourceKit inside it, then placed it inside Xcode 16, and it appears to be working, and fixed my issue [until now]
ahoppen commentedon Oct 2, 2024
Oh, that’s interesting that you’re also seeing excessive memory usage on macOS. I haven't seen that before.
Could you try reproducing the problem, run
leaks --outputGraph=/tmp sourcekit-lspand then share the.memgraphfile that is being generated the command? I’m hoping that will show us where the memory allocations are from.iMostfa commentedon Oct 2, 2024
@ahoppen i will try, when it happens i'm running against time to kill SourceKit-lsp before my device is freezed 🥶
i can also confirm that since i started using sourcekit-lsp from Xcode 15 the issue isn't appearing
ahoppen commentedon Oct 2, 2024
I think it would be valuable to see the graph when SourceKit-LSP is at ~2GB. That’s already more than it should take and should contain the culprit who’s using the memory.
iMostfa commentedon Oct 8, 2024
@ahoppen
i just shared it with u over email, thanks for u
ahoppen commentedon Oct 9, 2024
Thanks for sharing the memgraph, @iMostfa 🙏🏽 With it, it was obvious that the failure cause is the same one as #1720.
Use an `AtomicInt32` to count `pendingUnitCount` instead of using `As…
ahoppen commentedon Oct 29, 2024
I tracked down the memory leak to a bug in libdispatch. The issue should be fixed by swiftlang/swift-corelibs-libdispatch#850.
m-buczek commentedon Jan 13, 2025
This error prevents me from working on Xcode 16.2.
@ahoppen Is there a chance to fix this bug in Xcode 16.x or do we have to wait for Xcode 17?
I can confirm that the workaround provided by @iMostfa works (thanks a lot!).
More detailed instructions:
sourcekit-lspbinary:Please note that Xcode will only work with System Integrity Protection disabled.
iMostfa commentedon Jan 13, 2025
@m-buczek it's interesting that you needed SIP to be disabled, for me it worked without disabling it.
btw @ahoppen can you confirm to us if the changes to sourcekit-lsp were merged to Xcode[or swift which later merged to Xcode]
ahoppen commentedon Jan 13, 2025
Thanks for also confirming that my PR above fixes the issue. The fix will be included in Swift 6.1. I can’t speak for Xcode’s release schedule.
terraputix commentedon May 22, 2025
Is anyone still having problems with this?
I am using Swift 6.1 installed via swiftly on Fedora 40 and
sourcekit-lspis heavily eating up my memory when working in Swift using VS Code or Zed.The leaked memory seems to result mostly from
operator new(unsigned long, std::align_val_t) in libstdc++.so.6.hamishknight commentedon May 28, 2025
@terraputix That seems surprising to me, that would imply we're leaking entire ASTContexts. Do you have a project you can share that reproduces the issue?
iMostfa commentedon Jun 7, 2025
i can confirm that something is leaking again, on Mac OS, sourcekit-lsp took up 48GB of ram.
unfortunately, i wasn't able to get a mem dump because the whole system freezed
ahoppen commentedon Jun 10, 2025
The macOS and Linux leak are probably unrelated because the Linux leak seems to be coming from sourcekitd. macOS runs sourcekitd out-of-process, so the leak here must be coming from a leak inside SourceKit-LSP itself.
@iMostfa and @terraputix Could you file separate issues for the leaks you are seeing and include the following information?
terraputix commentedon Jun 13, 2025
@ahoppen, @hamishknight I created a follow up issue with the desired information in swiftlang/swift#82362.
MahdiBM commentedon Aug 29, 2025
I want to mention I've also been experiencing a lot of leaks for a long time. I was blaming it on Cursor and simply reopen Cursor to fix, but lately noticed It's actually not Cursor. I'll be trying to catch the leak and see if it matches any of the cases reported above.
MahdiBM commentedon Sep 29, 2025
Just a report: I haven't noticed something that I could call a "leak", recently, on macOS.
The memory usage is still somewhat high (~6-12GB in a M1 16GB machine - swap is definitely saving me) but it doesn't just go up indefinitely.