Massive CPU usage and can't even do basic code completion

I created a basic Vapor project and am using source-lsp with Visual Studio Code. I have noticed that the CPU usage for sourcekit-lsp is well over 100% and that it is very slow. I can't even do basic code completion. Sometime after letting it settles down I will be able to hover over symbol names and get documentation. This is great. But as soon as I start to type something as simple as "print()" is says that
'expression resolved to an unused function'. print is a builtin in swift function and I can't even get code completion on it and it says it is an error. Also as soon as I get this error every time I hover over a symbol that was working before I now get "Loading...". So currently SourceKit-lsp is unusable. Eventually it comes back and the "print" does work but I don't understand why it is taking so long.

I have Xcode 11.5 installed with swift version 5.2.4. the VSCode server path setting is '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp'

Any help would be appreciated

Thanks

1 Like

There is a known issue with performance of global completions caused by json serialization performance when there are a large number of results

import Foundation
prin<here> // slow, returns 10,000+ results
object.metho<here> // fast, maybe 100s of results

This is something we know about and intend to address.

I wish there was a way to ignore all of the global C symbols. It would help so much, even in Xcode.

2 Likes

+1. This issue also makes the auto-complete in Monaco Editor extremely slow (the json blob can be over 10MB which needs to be sent via WebSocket).

I think another approach is to respect the key.codecomplete.requestlimit key to sourcekitd, rather than returning unbounded number of completion items

Well I have really tried to use SourceKit-LSP with VSCode but I find that it is almost unusable. I am running on macOS Catalina with Xcode 11.5. A lot of time I will start typing and code completion will not work. When I hover over any symbols it just says "Loading...". Eventually, sometimes in a minute or so it catches up. In the meantime the fans on my brand new MacBook Pro 13" laptop spin up and the CPU usage goes crazy.

So I am not sure what can be done.

Any suggestions?

Bruce

P.S. I am running a Vapor project which has a lot of Swift Packages.

Sounds like the LSP is compiling and indexing your project. Is that not expected when using an LSP with a compiled language?

Yes. This is true. But even after I build the project which should rebuild the indexes. I still have this problem. What I might do over the next few days is create a video that show this issue. What I don't understand is that as soon as I start adding logic to a class by maybe creating a new method or calling an already existing method in one of my imported packages it just starts to randomly stop working properly and just bogs down.

Should be much faster now in master branch: Code-completion performance improvement via server-side filtering

Terms of Service

Privacy Policy

Cookie Policy