LoginSignup
2
2

More than 1 year has passed since last update.

MacでWebKitのビルド時間を計測してみる

Last updated at Posted at 2022-03-13

背景

  • iOSエンジニアとしては、Macのスペックにより、ビルド時間はどれくらい違うのかを知りたいところ

やること

  • ビルドにものすごい時間がかかるプロジェクトとして有名な WebKit をビルドしてみる
  • モデルごとに WebKit のビルド時間を計測して比較する
    • 出来れば同じ環境(コミット)でビルドしたい(が、手間がかかりそうなので最新masterでビルドする)

ビルド時間の計測結果

モデル デバッグビルド時間 WebKit の Commit Date
M1 Pro 16” MacBook Pro (2021) 16m:48s 2022.03.06
M1 Pro 16” MacBook Pro (2021) 18m:10s 2022.06.30
M2 13” MacBook Pro (2022) 24m:33s 2022.06.30

参考サイト: M1搭載MacBook、コードコンパイルはMac Pro並、16インチMBPを圧倒 - iPhone Mania

モデル コードコンパイル、テスト完了時間
M1 Mac mini (2020) 19m:32s
Intel Mac Pro (2019) 20m:11s
M1 13” MacBook Pro (2020) 20m:43s
M1 13” MacBook Air (2020) 25m:5s
Intel 16” MacBook Pro (2019) 26m:56s
Intel 13” MacBook Pro (2020) 46m:10s

※各モデルで環境(コミット、メモリなど)は違うのでご注意ください

環境

  • MacBook Pro (16インチ、2021)

    • チップ Apple M1 Pro
    • メモリ 16 GB
    • macOS Monterey 12.1
    • Xcode 13.1
    • commit 716d2d9 (2022.03.06)
  • MacBook Pro (16インチ、2021)

    • チップ Apple M1 Pro
    • メモリ 16 GB
    • macOS Monterey 12.4
    • Xcode 13.4.1
    • commit 849beda (2022.06.30)
  • MacBook Pro (13インチ、2022)

    • チップ Apple M2
    • メモリ 16 GB
    • macOS Monterey 12.4
    • Xcode 13.4.1
    • commit 849beda (2022.06.30)

結論

  • さまざまな困難を乗り越える覚悟を決め、やっと重い腰を上げて WebKit のビルドを始めてみたが、(最新 master のビルドに関しては)あっけないぐらい問題なく終わってしまった
  • ビルド時間に関しては、高性能コアの数よりも(高効率コアでも良いので)全体のコア数に比例してビルド時間は速くなりそう
    • (私は高性能コアが4コアから8コアに増えたら、ビルド時間が1/2とは言わなくても大幅に短縮されるのかもと勘違いしていた)
    • (Mac Studio の20コアや次期 Mac Pro なら、ビルド時間が10分以下になるかも)
  • やはり、高性能コアの力は大きかった
  • WebKitのビルド時間はバージョンによってそれほど変わらないだろうと思っていたが、そんなことは無さそう
    • バージョン(Webkit, OS, Xcode)によって結構ビルド時間は変わりそう

以下詳細

以下に試したことのメモ書きを残しておきます。


WebKitのビルド手順

ReadMe

WebKit/ReadMe.md at main · WebKit/WebKit · GitHub

clone

Cloning the Git SVN Repository

まずはクローン

  • git clone https://github.com/WebKit/WebKit.git WebKit

結果

  • クローン時間: 約30分ぐらい
  • WebKitディレクトリの容量: 12.1GB
$ git clone https://github.com/WebKit/WebKit.git WebKit
Cloning into 'WebKit'...
remote: Enumerating objects: 4865449, done.
remote: Counting objects: 100% (82/82), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 4865449 (delta 25), reused 34 (delta 20), pack-reused 4865367
Receiving objects: 100% (4865449/4865449), 8.12 GiB | 5.67 MiB/s, done.
Resolving deltas: 100% (3973683/3973683), done.
Updating files: 100% (357145/357145), done.

コミットID

2022.03月のビルドで使用したブランチとコミット

build

Building macOS Port

ビルド実行

  • Tools/Scripts/build-webkit --debug
$ cd WebKit/
$ Tools/Scripts/build-webkit --debug
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project libwebrtc.xcodeproj -UseSanitizedBuildSystemEnvironment=YES -ShowBuildOperationDuration=YES -configuration Debug SYMROOT=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild OBJROOT=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild SHARED_PRECOMPS_DIR=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/PrecompiledHeaders ARCHS=x86_64 SDKROOT=macosx -UseNewBuildSystem=NO

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES
    ShowBuildOperationDuration = YES
    UseNewBuildSystem = NO
    UseSanitizedBuildSystemEnvironment = YES

Build settings from command line:
    ARCHS = x86_64
    OBJROOT = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild
    SDKROOT = macosx
    SHARED_PRECOMPS_DIR = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/PrecompiledHeaders
    SYMROOT = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild

Prepare build
note: The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Project Settings.
=== BUILD TARGET webm OF PROJECT libwebrtc WITH CONFIGURATION Debug ===

Check dependencies

...

** BUILD SUCCEEDED ** [7.868 sec]


====================================================================
 WebKit is now built (29m:17s).
 To run Safari with this newly-built code, use the
 "Tools/Scripts/run-safari" script.
====================================================================

もしや、10分ぐらいでビルドが終わるのではないかと期待していたが、なんと、ビルド時間は29分!

何かがおかしい。
ログを良くみたら、ARCHS=x86_64とか書いてある。

あっ、別の調査でターミナルの設定を「Rossetaを使用して開く」にしていたのを忘れていた。
後でやり直す。

run

Safariで実行

With Safari and Other macOS Applications

  • Tools/Scripts/run-safari --debug
$ Tools/Scripts/run-safari --debug
Starting SafariForWebKitDevelopment with DYLD_FRAMEWORK_PATH set to point to built WebKit in /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/Debug.
2022-03-06 18:55:24.956 SafariForWebKitDevelopment[34021:12898444] +[NSXPCSharedListener endpointForReply:withListenerName:]: an error occurred while attempting to obtain endpoint for listener 'SandboxBroker': Connection invalid
2022-03-06 18:55:24.968 SafariForWebKitDevelopment[34021:12898436] could not create directory "/Users/[HOGE]/Library/Caches/com.apple.Safari/WebKitCache/OfflineWebApplicationCache" for future sandbox extension, error Error Domain=NSCocoaErrorDomain Code=513 "フォルダ“WebKitCache”にファイル“OfflineWebApplicationCache”を保存するためのアクセス権がありません。" UserInfo={NSFilePath=/Users/[HOGE]/Library/Caches/com.apple.Safari/WebKitCache/OfflineWebApplicationCache, NSUnderlyingError=0x6000006e99b0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

→権限エラーで動かない。
WebKitを動かすことは目的ではないので、今回はパスする。

シミュレータで実行

iOS Simulator

  • run-safari --debug --ios-simulator
$ Tools/Scripts/run-safari --debug --ios-simulator
Can't find built framework at "/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/Debug-iphonesimulator/JavaScriptCore.framework/JavaScriptCore".

→JavaScriptCore.frameworkが見つからずにエラーになる。
前に何かあった気がするが思い出せない。今回はパスする。


Nextチャレンジ

ターミナルの設定から「Rossetaを使用して開く」のチェックを外す

別の調査でターミナルの設定「Rossetaを使用して開く」のチェックを入れたままだったので、チェックを外して、ターミナルを再起動

WebKitBuildフォルダを削除

WebKitBuildフォルダを削除して、一度クリーンな状態に戻す

"WebKitBuild"ディレクトリの容量: (21.27 GB)

ビルドをやり直し

Tools/Scripts/build-webkit --debug

$ Tools/Scripts/build-webkit --debug
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project libwebrtc.xcodeproj -UseSanitizedBuildSystemEnvironment=YES -ShowBuildOperationDuration=YES -configuration Debug SYMROOT=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild OBJROOT=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild SHARED_PRECOMPS_DIR=/Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/PrecompiledHeaders ARCHS=arm64 SDKROOT=macosx -UseNewBuildSystem=NO

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES
    ShowBuildOperationDuration = YES
    UseNewBuildSystem = NO
    UseSanitizedBuildSystemEnvironment = YES

Build settings from command line:
    ARCHS = arm64
    OBJROOT = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild
    SDKROOT = macosx
    SHARED_PRECOMPS_DIR = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/PrecompiledHeaders
    SYMROOT = /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild

Prepare build
note: The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Project Settings.
=== BUILD TARGET webm OF PROJECT libwebrtc WITH CONFIGURATION Debug ===

Check dependencies

...

** BUILD SUCCEEDED ** [0.650 sec]


====================================================================
 WebKit is now built (17m:16s).
 To run Safari with this newly-built code, use the
 "Tools/Scripts/run-safari" script.
====================================================================

ビルド時間: 17分16秒

M1チップ搭載MacBook Pro の 20分 よりも速くなった!
さすがに、ビルド時間が10分になることはないな。

再起動してターミナル以外立ち上げない状態で再度build

$ Tools/Scripts/build-webkit --debug
...
====================================================================
 WebKit is now built (16m:48s).
 To run Safari with this newly-built code, use the
 "Tools/Scripts/run-safari" script.
====================================================================

念のために、余計なアプリを立ち上げないで計測をやり直してみたら、ビルド時間が30秒弱縮まった。


ビルドスクリプトの中身を確認してみる

スクリプトはperlで書かれている

WebKit/build-webkit at main · WebKit/WebKit · GitHub

option設定

スクリプトを読むと色々なオプションがあるよう

Usage: $programName [options] [options to pass to build system]
  -h, --help                        Show this help message
  -v, --verbose                     Show verbose build output
  --clean                           Cleanup the build directory
  --generate-project-only           Only generate project files
  --debug                           Compile with Debug configuration
  --release                         Compile with Release configuration
  --sdk=<sdk>                       Use a specific Xcode SDK (Apple platforms only)
  --ios-device                      Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
  --device                          DEPRECATED alias of --ios-device
  --ios-simulator                   Use "iphonesimulator.internal" SDK if installed, else "iphonesimulator" SDK (iOS only)
  --simulator                       DEPRECATED alias of --ios-simulator
  --tvos-device                     Use "appletvos.internal" SDK if installed, else "appletvos" SDK (tvOS only)
  --tvos-simulator                  Use "appletvsimulator" (tvOS only)
  --watchos-device                  Use "watchos.internal" SDK if installed, else "watchos" SDK (watchOS only)
  --watchos-simulator               Use "watchsimulator" (watchOS only)
  --coverage                        Enable code coverage support (Mac only)
  --analyze                         Enable static anaylsis (Apple platforms only)
  --lto-mode=<mode>                 Set Link Time Optimization mode (full, thin, or none) (LLVM only)
  --[no-]xcbuild                    DEPRECATED use of XCBuild or not
  --[no-]use-workspace              Use WebKit.xcworkspace and XCBuild (Apple platforms only)
  --ftw                             Build the FTW Windows port
  --gtk                             Build the GTK+ port
  --wpe                             Build the WPE port
  --wincairo                        Build using Cairo (rather than CoreGraphics) on Windows
  --playstation                     Build the PlayStation port
  --inspector-frontend              Copy Web Inspector user interface resources to the build directory
  --prefix=<path>                   Set installation prefix to the given path (CMake only, except Windows)
  --makeargs=<arguments>            Optional Makefile flags
  --cmakeargs=<arguments>           One or more optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
  --minimal                         No optional features, unless explicitly enabled
  --no-experimental-features        No experimental features, unless explicitly enabled (CMake only)
  --only-webkit                     Build only the WebKit project
  --skip-library-update             Skip the check to see if windows libraries are up to date
  --[no-]use-ccache                 Enable (or disable) CCache, if available
  --export-compile-commands         Generate compile_commands.json (Apple platforms only)

clean

--cleanオプションを指定すれば、クリーンアップができるらしい。

Tools/Scripts/build-webkit --clean

試したところ、"WebKitBuild"ディレクトリが無くなる訳ではなく、
"WebKitBuild"ディレクトリ内の各種ファイルが削除されるようだが、詳細は未調査。


参考サイト


参考サイトとの差分を調査

2020年11月19日のコミットを抽出

$ git log --oneline --after '2020/11/18' --before '2020/11/19'
619bfcb05b4a Resync web-platform-tests/WebIDL tests from upstream https://bugs.webkit.org/show_bug.cgi?id=219120
916d5c1c186d REGRESSION (r269895): Google Maps expanded route options are missing background color https://bugs.webkit.org/show_bug.cgi?id=219119 <rdar://problem/71510412>
...

参考: git log で特定の期間のログだけを出力する方法 | gotohayato.com

2020年11月19日のコミットとの差分

とりあえず、"619bfcb" ( 19 Nov 2020 )を使ってdiffをとってみる。

→凄まじい数の差分があるな

→当時のコミットと最新のコミットでビルド時間が極端に変わらないことを確認したかったが、差分からエビデンスを取るのは諦める。
checkoutして、ビルドしたほうが早そう。

2020年11月19日のコミットに戻す

git checkout 619bfcb05b4a

参考: 【Git】一時的に過去のcommitに戻りたい - Qiita

2020年11月19日のコミットでビルド

Tools/Scripts/build-webkit --debug

** BUILD FAILED **


The following build commands failed:
	CompileC /Users/[HOGE]/Desktop/Git/WebKit/WebKitBuild/ANGLE.build/Debug/ANGLE\ (static).build/Objects-normal/arm64/SystemInfo_macos.o src/gpu_info_util/SystemInfo_macos.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

→"SystemInfo_macos.o" でエラーになる。MacOSの問題だろうか?

もうひとつ前のコミットでビルドしてみる

git checkout 916d5c1c186d

→同じエラーになる

当時の安定版のタグを使ってみる

$ git tag -l --format='%(taggerdate) %(refname)' --sort=-taggerdate
...
Wed Dec 1 14:00:59 2021 -0800 refs/tags/Safari-613.1.9.1
Mon Nov 29 18:33:06 2021 -0800 refs/tags/Safari-612.3.6.1.6
Mon Nov 29 18:25:52 2021 -0800 refs/tags/Safari-612.3.6.0.4
Thu Nov 18 19:12:56 2021 -0800 refs/tags/Safari-612.3.6.1.5
Thu Nov 18 13:47:54 2021 -0800 refs/tags/Safari-613.1.9
Thu Nov 18 10:42:05 2021 -0800 refs/tags/Safari-613.1.8.3
Wed Nov 17 15:07:16 2021 -0800 refs/tags/Safari-612.3.6.1.4
Wed Nov 17 11:21:55 2021 -0800 refs/tags/Safari-613.1.9.0.1
Tue Nov 16 18:13:35 2021 -0800 refs/tags/Safari-612.3.6.3.1
Tue Nov 16 18:12:07 2021 -0800 refs/tags/Safari-612.3.6.2.2

日付が近い以下を使ってみる。
Thu Nov 18 19:12:56 2021 -0800 refs/tags/Safari-612.3.6.1.5

checkout
git checkout Safari-612.3.6.1.5

→やはり、エラーになってしまう。
MacOSのバージョン問題なのかもしれないが、よく分からない。
とりあえず、最新コミットではビルドできたので、これ以上深追いしない。

→ 参考サイトと同じ環境でビルドをしたかったが、今回は断念

2
2
0

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
2
2