-
Notifications
You must be signed in to change notification settings - Fork 304
High memory usage #1541
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
Comments
Synced to Apple’s issue tracker as rdar://130844901 |
Hey @ebak, A couple of questions:
|
Hi, Now I don't have possibility to try it on the machine with 8 CPUs, maybe next week.
I attach screenshots of
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 ( |
Just by editing the same code, the memory usage quickly goes up to 45% (3.6GB maybe): Maybe unrelated but The dependencies ( Sad the 8GB RAM is hardly enough for IDE assisted development. |
I have been able to reproduce the memory growth by working on the SourceKit-LSP codebase in VS Code on Ubuntu 22.04. |
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.) |
I saw the memory issue with a 6.0 toolchain. |
Checking if this allows us to reproduce the memory issues from swiftlang/sourcekit-lsp#1541 on macOS.
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] |
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 |
@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 |
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. |
@ahoppen |
…yncQueue` Adding an item to `AsyncQueue<Serial>` is linear in the number of pending queue items, thus adding n items to an `AsyncQueue` before any can execute is in O(n^2). This decision was made intentionally because the primary use case for `AsyncQueue` was to track pending LSP requests, of which we don’t expect to have too many pending requests at any given time. `SourceKitIndexDelegate` was also using `AsyncQueue` to track the number of pending units to be processed and eg. after indexing SourceKit-LSP, I have seen this grow up to ~20,000. With the quadratic behavior, this explodes time-wise. Turns out that we don’t actually need to use a queue here at all, an atomic is sufficient and much faster. Independently, we should consider mitigating the quadratic behavior of `AsyncQueue<Serial>` or `AsyncQueue` in general. Fixes swiftlang#1541 rdar://130844901
I tracked down the memory leak to a bug in libdispatch. The issue should be fixed by swiftlang/swift-corelibs-libdispatch#850. |
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:
sudo cp /<PATH_TO_XCODE_15.4>/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
Please note that Xcode will only work with System Integrity Protection disabled. |
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. |
Description
I have recently tried out the stable tool-chain (installed with
swiftly
onManjaro Linux
) withVSCode
and itsSwift 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.
The text was updated successfully, but these errors were encountered: