DerivedData
Xcode會在文件系統中集中的緩存臨時信息。
每次對Xcode iOS項目進行clean、build或者在iOS虛擬機上launch,Xcode都會在DeriveData文件夾中進行讀寫操作。換句話說,就是將Derived Data的讀寫從硬盤移動到內存中。
DeriveData文件夾中包含了所有的build信息、debug- 和 release- built targets以及項目的索引。當遇到零散索引(odd index)問題(代碼塊補全工作不正常、經常性的重建索引、或者運行項目緩慢)時,它可以有效地刪除衍生數據。刪除這個文件夾將會導致所有Xcode上的項目信息遭到破壞。
Step 1
將DeriveData下的文件刪除:
C代碼 收藏代碼
rm -rf ~/Library/Developer/Xcode/DerivedData/*
C代碼 收藏代碼
hdid -nomount ram://4194304
刪除的這些數據,Xcode會在Build時重新寫入的。
Step 2
在~/Library/Developer/Xcode/DerivedData.上部署安裝2 GB大小的RAM磁盤。
進到~/Library/Developer/Xcode/DerivedData.
C代碼 收藏代碼
cd ~/Library/Developer/Xcode/DerivedData
創建2 GB的RAM磁盤(size的計算公式 size = 需要分配的空間(M) * 1024 * 1024 / 512):
C代碼 收藏代碼
hdid -nomount ram://4194304
此行命令后將會輸出RAM磁盤的驅動名字:/dev/diskN(N為數字)。
初始化磁盤:
C代碼 收藏代碼
newfs_hfs -v DerivedData /dev/rdiskN
有以下輸出:
Initialized /dev/rdisk3 as a 2 GB case-insensitive HFS Plus volume
安裝磁盤:
C代碼 收藏代碼
diskutil mount -mountPoint ~/Library/Developer/Xcode/DerivedData /dev/diskN
這會在已存在的DeriveData上安裝一個卷,用于隱藏舊的文件。這些文件仍會占據空間,但在移除RAM磁盤之前都無法訪問。
在重啟或從Finder中彈出RAM磁盤時,磁盤中的內容將會消失。下次再創建磁盤時,Xcode將會重新構建它的索引和你的項目中間文件。
創建虛擬磁盤后, 并不是直接占用掉所有分配的空間, 而是根據虛擬磁盤中的文件總大小來逐漸占用內存.
注:如果創建的虛擬磁盤已滿, 會導致編譯的失敗. 此時清除掉Derived Data后重新編譯, 就算有足夠的空間也還是有可能會導致編譯失敗. 重啟Xcode可以解決此問題.
對手頭Demo進行編譯測試,由于編譯本身讀寫內容較少,耗時較短,都在10s到20s之內,所以提速感覺不明顯,在1s到2s間(10%左右),也許應用到較大的項目中會有比較好的體現。
參考: Reduce XCode build times
【iOS Tip】提高Xcode編譯速度DerivedData
Xcode會在文件系統中集中的緩存臨時信息。
每次對Xcode iOS項目進行clean、build或者在iOS虛擬機上launch,Xcode都會在DeriveData文件夾中進行讀寫操作。換句話說,就是將Derived Data的讀寫從硬盤移動到內存中。
DeriveData文件夾中包含了所有的build信息、debug- 和 release- built targets以及項目的索引。當遇到零散索引(odd index)問題(代碼塊補全工作不正常、經常性的重建索引、或者運行項目緩慢)時,它可以有效地刪除衍生數據。刪除這個文件夾將會導致所有Xcode上的項目信息遭到破壞。
Step 1
將DeriveData下的文件刪除:
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=rm%20-rf%20~%2FLibrary%2FDeveloper%2FXcode%2FDerivedData%2F*" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
- rm -rf ~/Library/Developer/Xcode/DerivedData/*
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=hdid%20-nomount%20ram%3A%2F%2F4194304" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
-
hdid -nomount ram:
//4194304
刪除的這些數據,Xcode會在Build時重新寫入的。
Step 2
在~/Library/Developer/Xcode/DerivedData.上部署安裝2 GB大小的RAM磁盤。
進到~/Library/Developer/Xcode/DerivedData.
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=cd%20~%2FLibrary%2FDeveloper%2FXcode%2FDerivedData" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
- cd ~/Library/Developer/Xcode/DerivedData
創建2 GB的RAM磁盤(size的計算公式 size = 需要分配的空間(M) * 1024 * 1024 / 512):
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=hdid%20-nomount%20ram%3A%2F%2F4194304" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
-
hdid -nomount ram:
//4194304
此行命令后將會輸出RAM磁盤的驅動名字:/dev/diskN(N為數字)。
初始化磁盤:
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=newfs_hfs%20-v%20DerivedData%20%2Fdev%2FrdiskN" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
- newfs_hfs -v DerivedData /dev/rdiskN
有以下輸出:
Initialized /dev/rdisk3 as a 2 GB case-insensitive HFS Plus volume
安裝磁盤:
C代碼
<embed wmode="transparent" src="http://815222418.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=diskutil%20mount%20-mountPoint%20~%2FLibrary%2FDeveloper%2FXcode%2FDerivedData%20%2Fdev%2FdiskN" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14"> [](javascript:void() "收藏這段代碼")
- diskutil mount -mountPoint ~/Library/Developer/Xcode/DerivedData /dev/diskN
這會在已存在的DeriveData上安裝一個卷,用于隱藏舊的文件。這些文件仍會占據空間,但在移除RAM磁盤之前都無法訪問。
在重啟或從Finder中彈出RAM磁盤時,磁盤中的內容將會消失。下次再創建磁盤時,Xcode將會重新構建它的索引和你的項目中間文件。
創建虛擬磁盤后, 并不是直接占用掉所有分配的空間, 而是根據虛擬磁盤中的文件總大小來逐漸占用內存.
注:如果創建的虛擬磁盤已滿, 會導致編譯的失敗. 此時清除掉Derived Data后重新編譯, 就算有足夠的空間也還是有可能會導致編譯失敗. 重啟Xcode可以解決此問題.
對手頭Demo進行編譯測試,由于編譯本身讀寫內容較少,耗時較短,都在10s到20s之內,所以提速感覺不明顯,在1s到2s間(10%左右),也許應用到較大的項目中會有比較好的體現。