I'm ok Xcode 8.3.2 and SourceKitService is using all my CPU. I read a lot of questions here on stackoverflow, but I could't find a real solution.
What I tried:
- Clean project data: cmd+shift+alt+K
- Delete derivedData folder
- reboot Xcode
- redownload the project code from git
Nothing worked. I understood the issue is probably related to some code, but how can I spot where is the issue? My project is quite big...
Currently Xcode is unusable...
Thanks for your help
SourceKit has always been CPU and RAM hungry, slow and prone to crashes. It gets (in my experience) a little better with Xcode 9.
One big problem is that many expressions in Swift have a large number of overloads. For type inference to work, all of them have to be tested. This is also the reason why compile times for Swift code are often a little bit longer.
Once SourceKit begins to work on such expressions, everything else has to wait.
You can help SourceKit by avoiding long expressions especially when using binary operators and chains of
map
,flatMap
andfilter
operations on collections and sequences, as the time complexity for resolving the return type on such expressions is exponential.You can try to reduce long type inference times by declaring the types of variables (
let a: X = expr
instead oflet a = expr
). In my experience, this also helps in closures for chainsmap
,filter
andflatMap
chains ({ param -> Result in ...}
instead of{ param in }
).You can use the
-Xfrontend -debug-time-function-bodies
flags in the Other Swift Flags build settings to get compile times for every function in your build report in Xcode, which can help you identify expressions which take long to process by the compiler and SourceKit. Detailed instructions can be found in this blog post.Other than that I don't know of any other solutions.