Any advice for a SourceKit-LSP bottleneck using the Build Server Protocol?

Hello!

I am using a Bazel build system, specifically this build-server (GitHub - spotify/sourcekit-bazel-bsp: iOS Development (and more) in alternative IDEs like Cursor / VSCode, for Bazel projects) with SourceKit-LSP.

One issue I’ve noticed, is each bazel build invocation (e.g, when responding to buildTarget/prepare among other requests) can take on average ~30 seconds to 1 minute for large iOS projects with millions of lines of swift code.

SourceKit-LSP’s SemanticIndexManager is an actor that blocks other requests until the BSP responds.

This means, that when the buildTarget/prepare request (or any other request) is sent to the BSP, all jump to definition / autocomplete stops working completely until the BSP responds a minute later.

AFAIK, SourceKit-LSP makes the assumption that these requests to the BSP will complete within a couple hundred milliseconds instead of in the 30 sec to 1 minute range.

I’m wondering whats the best way to overcome this bottleneck?

My thought process was, it would be ideal if SemanticIndexManager could continue to serve requests from the VSCode client to the LSP (e.g, jump to definition, auto complete, etc) whilst waiting for the BSP in parallel. Yes, this would mean the LSP might serve stale diagnostics for up-to ~30 seconds - 1 minute, but I feel like in my case, this would be a much better user experience.

Does anyone have any advice, or ideas to explore here? Would the only way to overcome this be to fork SourceKit-LSP? It would be ideal if there is a way to potentially overcome this without forking the repo.

Thank you so much!

Thanks for raising this but I don’t think your analysis is quite correct. SemanticIndexManager is actor and while actors don’t allow concurrent execution of two code blocks, an actor is able to handle new function invocations while it awaits a the result of a call, which is the case when it waits for preparation – and target preparation is very much expected to take seconds or even minutes.

To investigate this further, could you file an issue for this in GitHub - swiftlang/sourcekit-lsp: Language Server Protocol implementation for Swift and C-based languages and include the following logs in it:

  • log stream --predicate 'subsystem CONTAINS "sourcekit-lsp"' --signpost > /tmp/log.txt in Terminal
  • Reproduce the issue
  • Attach /tmp/log.txt to the issue

If you are able to enable extended logging as described in sourcekit-lsp/Documentation/Enable Extended Logging.md at main · swiftlang/sourcekit-lsp · GitHub before running the steps described above, that would definitely help us but even without extended logging, the log generated above should be helpful to see what’s going on.

Thank you so much for your reply!

You are right, I apologize for being mistaken in my post :folded_hands:

I just submitted an issue here and attached the logs reproducing the issue. Unfortunately, I wasn’t able to include the extended logging for privacy reasons.

Hopefully the logs can help us figure out the right direction to look in, it seems like its likely an issue with the BSP implementation/assumptions being made?

Thank you again for your time.