Thursday, September 28, 2017 [Tweets] [Favorites]

Measuring Swift Compile Times in Xcode 9

Jesse Squires:

As mentioned, after you add these flags you will start getting warnings. Keep in mind that if the threshold is too low, for example 10ms, then you will get a ton of warnings that cannot be fixed. Experiment with these threshold values and adjust as needed. I suggesting starting at 200 and tuning from there. If your code base is large, it might make more sense to use a higher value for your project (say 500) and try to decrease it over time. Otherwise, you’ll be spending a lot of time trying to get all functions and expressions to compile in under 200ms. Also, I recommend setting these flags only for DEBUG build configurations.

There are two common scenarios where Xcode will start emitting warnings with these flags: (1) very complex expressions or functions, and (2) expressions that omit explicit types and rely on type inference. To silence the warnings — and thus improve compile times — try breaking up expressions into smaller steps with intermediate variables, and adding explicit types to variable declarations and closure parameters.

Previously: Guarding Against Long Swift Compiles.

Update (2018-04-29): See also: Marcin Krzyzanowski.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment