Skip to content

Commit 462770e

Browse files
authored
Merge pull request #18 from fastred/xcode-10
Xcode 10
2 parents ce6da1f + 3d657dc commit 462770e

File tree

5 files changed

+17
-69
lines changed

5 files changed

+17
-69
lines changed

README.md

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Swift is constantly improving ❤️. For the time being, though, long compile t
88

99
# Table of contents
1010

11+
- [Incremental Compilation Mode with No Optimization](#incremental-compilation-mode-with-no-optimization)
1112
- [Type checking of functions and expressions](#type-checking-of-functions-and-expressions)
1213
- [Slowly compiling files](#slowly-compiling-files)
1314
- [Build active architecture only](#build-active-architecture-only)
1415
- [dSYM generation](#dsym-generation)
15-
- [Whole Module Optimization](#whole-module-optimization)
1616
- [Third-party dependencies](#third-party-dependencies)
1717
- [Modularization](#modularization)
1818
- [XIBs](#xibs)
@@ -21,6 +21,18 @@ Swift is constantly improving ❤️. For the time being, though, long compile t
2121
- [Enable concurrent Swift build tasks](#enable-concurrent-swift-build-tasks)
2222
- [Showing build times in Xcode](#showing-build-times-in-xcode)
2323

24+
# Incremental Compilation Mode with No Optimization
25+
26+
Until Xcode 10, it was common to enable [Whole Module Optimization](https://github.com/fastred/Optimizing-Swift-Build-Times/blob/ce6da1f3a47220259c3924df62f44f06bc45e222/README.md#whole-module-optimization) to speed up Debug builds. It was a workaround that's no longer needed in Xcode 10!
27+
28+
Currently, the recommended setup is to have `Incremental` `Compilation Mode` set for Debug builds and `Whole Module` for Release builds. Also, `No Optimization` should be chosen for `Optimization Level` setting of Debug builds.
29+
30+
<img src="assets/compilation-and-optimization@2x.png" width="551">
31+
32+
📖 Sources:
33+
34+
- [What's New in Swift – WWDC 2018](https://developer.apple.com/videos/play/wwdc2018/401/?time=657)
35+
2436
# Type checking of functions and expressions
2537

2638
Swift build times are slow mostly because of expensive type checking. By default Xcode doesn't show code that's slow to compile. You can instruct it to show slowly compiling functions and expressions, though by adding:
@@ -30,7 +42,7 @@ Swift build times are slow mostly because of expensive type checking. By default
3042

3143
to `Other Swift Flags` in build settings:
3244

33-
<img src="assets/times@2x.png" width="795">
45+
<img src="assets/times@2x.png" width="801">
3446

3547
Build again and you should now see warnings like these:
3648

@@ -110,50 +122,6 @@ Recommended setup:
110122

111123
- [Speeding up Development Build Times With Conditional dSYM Generation](http://holko.pl/2016/10/18/dsym-debug/)
112124

113-
# Whole Module Optimization
114-
115-
Another common trick is to:
116-
117-
- change `Optimization Level` to `Fast, Whole Module Optimization` for Debug configuration
118-
- add `-Onone` flag to `Other Swift Flags` **only for Debug configuration**
119-
120-
<img src="assets/wmo_9@2x.png" width="792">
121-
122-
What this does is it instructs the compiler to:
123-
124-
> It runs one compiler job with all source files in a module instead of one job per source file
125-
>
126-
> Less parallelism but also less duplicated work
127-
>
128-
> It's a bug that it's faster; we need to do less duplicated work. Improving this is a goal going forward
129-
130-
Note that incremental builds with minimal changes seem to be a bit slower under this setup. You should see a vast speedup (2x in many projects) in a worst-case scenario, though.
131-
132-
📖 Sources:
133-
134-
- [Developear - Speeding Up Compile Times of Swift Projects](http://developear.com/blog/2016/12/30/Speed-Swift-Compilation.html)
135-
- [Slava Pestov on Twitter: “@iamkevb It runs one compiler job with all source files in a module instead of one job per source file”](https://twitter.com/slava_pestov/status/911747257103302656)
136-
137-
## Whole Module Optimization for CocoaPods
138-
139-
If you use CocoaPods, you should also consider enabling WMO without optimization in your `Pods` project.
140-
To do that, you have to add the following `post_install` hook to your `Podfile`:
141-
142-
```ruby
143-
post_install do |installer|
144-
installer.pods_project.targets.each do |target|
145-
target.build_configurations.each do |config|
146-
if config.name == 'Debug'
147-
config.build_settings['OTHER_SWIFT_FLAGS'] = ['$(inherited)', '-Onone']
148-
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule'
149-
end
150-
end
151-
end
152-
end
153-
```
154-
155-
and then run `$ pod install`. Make sure to compare build times before and after this change to confirm there's an improvement.
156-
157125
# Third-party dependencies
158126

159127
There are two ways you can embed third-party dependencies in your projects:
@@ -220,33 +188,13 @@ Builds the app and all test targets. Runs all tests. Useful when working on code
220188

221189

222190
# Use the new Xcode build system
223-
In Xcode 9 Apple [quietly introduced a new build system](https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW878). This is a “preview” and is not enabled by default.
224-
It can be significantly faster than the default build system.
225-
To enable it, go to Workspace or Project Settings from the File menu in Xcode. There you can switch build systems to the new build system preview.
226-
227-
📖 Sources:
228-
229-
- [Faster Swift Builds with the New Xcode Build System](https://github.com/quellish/XcodeNewBuildSystem)
230-
231-
# Enable Concurrent Swift Build Tasks
232-
Xcode 9.2 has experimental support for increasing the number of concurrent build tasks for Swift projects. For some projects this may greatly improve build times. Note that when this option is enabled Xcode may use significantly more memory.
191+
In Xcode 9 Apple [introduced a new build system](https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW878). To enable it, go to Workspace or Project Settings from the File menu in Xcode. There you can switch build systems to the new build system.
233192

234-
To enable this feature, quit Xcode and enter this command in a Terminal window:
235-
236-
```
237-
$defaults write com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsExclusively -bool NO
238-
```
239-
240-
Test whether this benefits your project. For many projects it may not make a difference, but for others the savings may be very significant.
241-
To disable this feature enter this in a Terminal window and restart Xcode:
242-
243-
```
244-
$defaults delete com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsExclusively
245-
```
193+
<img src="assets/new_build_system@2x.png" width="536">
246194

247195
📖 Sources:
248196

249-
- [Even faster Swift build times with Xcode 9.2](https://github.com/quellish/XcodeConcurrentSwiftBuilds)
197+
- [Faster Swift Builds with the New Xcode Build System](https://github.com/quellish/XcodeNewBuildSystem)
250198

251199
# Showing build times in Xcode
252200
Finally, to be able to actually know whether your build times are improving, you should enable showing them in Xcode’s UI. To do that, run this from the command line:
52.4 KB
Loading

assets/new_build_system@2x.png

30.8 KB
Loading

assets/times@2x.png

-10.2 KB
Loading

assets/wmo_9@2x.png

-197 KB
Binary file not shown.

0 commit comments

Comments
 (0)