Last month, I attended a local iOS developer meeting in Seattle. Jeff Szuhay, a veteran programmer with 20+ years of experience, told me a way to improve the efficiency of iOS development. Compared to other programmers in the App startup time and architecture optimization experience Optimization Based on Jeff’s hardware level, imaginative, geek style. The following is his experience sharing and my personal measurements.
IOS black Technology
We all know Xcode in the run or compile time, there will be a lot of read and write operations. For example, if you call a picture from your hard disk, we’ll do that:
Letimage=UIImage (named: imageName)
Xcode at this time will go to your computer’s hard drive to find the pictures, read and write. Similar operations include access to files and so forth. If the number of read less, so innocuous, but once more, especially large projects in the later produced a large number of DerivedData on the hard disk, Xcode will spend a lot of time to drive at compile time (Disk) on these data read and write operations. More unfortunately, there are other problems such as hard disk failure.
Is the so-called “where the need for optimization, where you need a programmer, Jeff at this time as a white knight debut. Years of computer research allowed him to become very familiar with the overall computer architecture. The diagram below shows the computer structure shown by him.
thinking structure diagram
Computer structure diagram
This concise and clear to illustrate the basic structure of computer. The upper left corner is the brain of the computer, CPU, responsible for the core calculation and processing work; the upper right corner of memory (RAM), used to run the program and data exchange with CPU; the middle line is responsible for transmitting information and bus signals between each module; the downside is the basic System IO map.
Back to see our problem: Xcode is now running in RAM, and then to read and write data in the Storage data, then back to RAM. There are two bottlenecks in this way:
1, Storage speed is very slow. Even the most advanced SSD, its speed is 400 times slower than RAM’s.. That is, no matter how you optimize the software layer, its speed can not break through the bottleneck of SSD;
2, to keep the data transfer in between each module. There are also delays and unnecessary time consumption during delivery.
In view of the above two bottlenecks, Jeff believes that if we can make all the read and write operation in the memory (RAM) to complete, it can greatly improve the working efficiency of Xcode. The question is, how do you achieve it?
Method is very simple, it can be divided into two steps
1, RAM. Make one out of memory for Xcode to use.
2, Xcode connection. Connect Xcode to our exclusive memory space.
The following is to witness the miracle of the moment.
First step, create a.Sh file. The code reads as follows.
SIZE=1024#size in MB for ramdisk.
Second step, run the.Sh file. Knock on the command line.
command line code
After you will find that you will be more of a ramdisk memory space, there are about 1 GB in size.
Third, Xcode connection. Xcode -> Preferences -> Locations -> Locations Tab; configure DerivedData.
Advanced… Also configure the
as shown below
Is above all the steps. This time you can enjoy the flying development. All files in Project are now in memory, and are theoretically faster by an order of magnitude than SSD.
Matters needing attention
1, a reasonable allocation of memory space. I’ve allocated 1GB of memory here when the hard disk is enabled because my computer itself has 16GB of memory space. If your computer has only 4GB of memory, I don’t recommend using this method, or suggest allocating only 256M space to Xcode. In short, pay attention to insufficient memory or overflow.
2, just put the DerivedData in Ram Disk. To limit speed, of course you can put all of the App related files in memory space. But you know, the Ram Disk we created is essentially memory, and when it is powered off or restarted, the data in Ram Disk is lost. And DerivedData can be re generated, so in Ram Disk, you can maximize the speed of reading in Xcode development, and very safe.