SourceKitService eating all CPU on Xcode 8.3.2
Asked Answered
K

4

7

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

Kensell answered 4/6, 2017 at 9:59 Comment(0)
M
8

This is not really a "fix" because it will also be detrimental to people who rely on having live issues shown to them. But if you go to Preferences->General and switch off "Show live issues" then xcode runs like a bunny on a cool spring day. I prefer that over having to force quit SourceKit service every now and then.

Marutani answered 18/9, 2017 at 14:59 Comment(1)
this at least makes XCode usable again. thanks so muchNavarro
H
2

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 and filter 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 of let a = expr). In my experience, this also helps in closures for chains map, filter and flatMap 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.

Hemistich answered 5/8, 2017 at 17:12 Comment(0)
R
2

One of the really nice solutions I had been using for quite some time now is using Build Time Analyzer for Swift tool to analyze my codebase and show a detailed list of all the methods and functions that take huge time to process and compile.

enter image description here

I would then refactor the necessary files and declarations and measure my results again. Repeat this until you have really nice and fast compilation time results.

There's also a nice list with advices on Swift compilation times.

Rakia answered 9/8, 2017 at 16:20 Comment(0)
N
0

I have seen a similar issue on an application with multiple storyboards, where, interestingly, Xcode had trouble just with one of the storyboards. Working on that storyboard would be really hard, with the CPU going full blast.

Our solution was to get to that storyboard an split it further into smaller storyboards. This can be easily done by selecting a few scenes and then Editor -> Refactor to Storyboard... on the menu.

enter image description here

This change made it much easier to work with the new smaller storyboards.

Nall answered 9/8, 2017 at 16:8 Comment(1)
This will replace my old storyboard into new one with only one view controller. Better test it or I shall report to the community.Eyelet

© 2022 - 2024 — McMap. All rights reserved.