sourcekit-lsp: High memory usage
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (17 by maintainers)
Commits related to this issue
- [DO NOT MERGE] Use default cache on macOS Checking if this allows us to reproduce the memory issues from https://github.com/swiftlang/sourcekit-lsp/issues/1541 on macOS. — committed to ahoppen/swift by ahoppen 2 years ago
- Use an `AtomicInt32` to count `pendingUnitCount` instead of using `AsyncQueue` Adding an item to `AsyncQueue<Serial>` is linear in the number of pending queue items, thus adding n items to an `AsyncQ... — committed to ahoppen/sourcekit-lsp by ahoppen 2 years ago
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.
I tracked down the memory leak to a bug in libdispatch. The issue should be fixed by https://github.com/swiftlang/swift-corelibs-libdispatch/pull/850.
I saw the memory issue with a 6.0 toolchain.
Thanks for sharing the memgraph, @iMostfa 🙏🏽 With it, it was obvious that the failure cause is the same one as https://github.com/swiftlang/sourcekit-lsp/pull/1720.
@ahoppen i just shared it with u over email, thanks for u
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]
I have been able to reproduce the memory growth by working on the SourceKit-LSP codebase in VS Code on Ubuntu 22.04.