Reputation: 2153
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:
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
Upvotes: 7
Views: 1562
Reputation: 2576
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.
Upvotes: 8
Reputation: 12051
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.
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.
Upvotes: 2
Reputation: 19682
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.
This change made it much easier to work with the new smaller storyboards.
Upvotes: 0
Reputation: 12109
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.
Upvotes: 2