Improve Xcode compilation performance, RAM disk compilation

 

DerivedData

 

Xcode caches temporary information centrally in the file system.

Every time an Xcode iOS project is cleaned, built, or launched on an iOS virtual machine, Xcode reads and writes to the DeriveData folder. In other words, it is to move the read and write of Derived Data from the hard disk to the memory.

The DeriveData folder contains all build information, debug- and release-built targets, and project indexes. It effectively removes derived data when encountering odd index problems (block completion not working properly, frequent index rebuilds, or slow running projects). Deleting this folder will destroy all project information on Xcode.

 

Step 1

Delete the files under DeriveData:

rm -rf ~/Library/Developer/Xcode/DerivedData/*

The deleted data will be rewritten by Xcode during Build.

 

Step 2

Deploy a 2 GB RAM disk on ~/Library/Developer/Xcode/DerivedData.

进到~/Library/Developer/Xcode/DerivedData.

cd ~/Library/Developer/Xcode/DerivedData

 

Create a 2 GB RAM disk (calculation formula for size  size = 需要分配的空间(M) * 1024 * 1024 / 512):

hdid -nomount ram://4194304

 After this command, the drive name of the RAM disk will be output: /dev/diskN (N is a number).

 

Initialize the disk:

newfs_hfs -v DerivedData /dev/rdiskN

     Initialized /dev/rdisk3 as a 2 GB case-insensitive HFS Plus volume

 

Install disk:

diskutil mount -mountPoint ~/Library/Developer/Xcode/DerivedData /dev/diskN

This will mount a volume on top of the existing DeriveData to hide old files. These files will still take up space, but will not be accessible until the RAM disk is removed.

 

On reboot or ejecting the RAM disk from the Finder, the contents of the disk will disappear. The next time you create the disk, Xcode will rebuild its index and your project intermediate files.

 

After the virtual disk is created, it does not directly occupy all the allocated space, but gradually occupies the memory according to the total size of the files in the virtual disk.


Note: If the created virtual disk is full, the compilation will fail. At this time, clear the Derived Data and then recompile, even if there is enough space, the compilation may still fail. Restarting Xcode can solve this problem.

 

Compiling and testing the demo at hand, because the compilation itself has less content to read and write, and it takes less time, all within 10s to 20s, so the speedup is not obvious. It may be applied to larger projects between 1s and 2s. There is a better performance.

 

参考:   Reduce XCode build times

 

            [iOS Tip] Improve Xcode compilation speed

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326146699&siteId=291194637