LoginSignup
29

More than 5 years have passed since last update.

Xcode9でビルド時間を短縮する

Last updated at Posted at 2017-11-13

Xcode9から、BuildSystem を変更することで、ビルド時間を短縮することができます。

Build Systemってなんだ

Whats New in Xcode (Xcode9に、次のように書いてあります

New in Xcode 9 – Preview of a new build system written in Swift. Currently, This system is optional but it will become the default in a future version of Xcode

  • Added a preview of a new build system written in Swift.
  • Provides higher reliability.
  • Catches many project configuration problems.
  • Improves overall build-system performance. Note, build system performance does not include the compilers, linkers, and other tools used by the build system.

To opt into the new build system for a project or workspace, choose File > Project Settings or File > Workspace Settings, and then choose New Build System (Preview) for the Build System type. For notes on compatibility with existing projects, see the Xcode Release Notes.

簡単にまとめると、

  • 現在はオプションとして選択すると使えるようになる(将来的にはデフォルトになる)
  • Swiftで書かれたビルドシステム
  • 高い信頼性、プロジェクト構成の問題のキャッチ
  • ビルドシステム全体のパフォーマンス向上

のようです。早くなりそうな感じがしますね!

試した環境

  • Xcode 9.1
  • MacbookPro 15インチ late2016 (TouchBar付、2.9GHz、4コア)

ビルド時間の計測方法については以下が参考になります
- Swiftのメソッド毎のコンパイル時間を計測してビルド時間を短縮する

あとは、PCが4コアなので以下のコマンドをターミナルで叩いています。

$ defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4

Workspaceの設定を変更する

Xcodeの[File]->[WorkSpace Settings...] を開きます

スクリーンショット 2017-11-13 14.06.13.png

Build Systemを変更する

[Shared Workspace Settings:]の項目のプルダウンで、 NewBuildSystem(Preview)に変更します。

スクリーンショット 2017-11-13 14.06.21.png

スクリーンショット 2017-11-13 14.29.31.png

あとはいつもどおりビルドするだけです。
ビルド中、画面上部の表示がこんな感じになります

スクリーンショット 2017-11-13 14.38.37.png

(Preview)とあるので、今後仕様や性能が変わる可能性はありそうです。

また、この設定は各Project毎に行う必要があります。

どれくらい早くなるのか

手元に巨大なProjectがなかったので、ファイル180程度のもの+CocoaPodsのビルドありで試しましたが、
BuildTimeAnylizerを用いて計測したところ

  • 前: 174秒
  • 後: 143秒

となりました。なので、およそ20%ほど早くなったようです。(何度か計測して平均...まではやっていません)
大きいProjectほど恩恵は得られそうですね。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29