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

Most upvoted comments

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:

  1. Disable System Integrity Protection: Apple Documentation
  2. Get Xcode 15.4: Download Link (requires login to a developer account) and unzip archive.
  3. Replace sourcekit-lsp binary:
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.

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.