How to make Xcode in reading and writing speed 100 times?

How to make Xcode in reading and writing speed 100 times?

Last month, I took part in a local iOS developer meeting in Seattle. Jeff Szuhay as a senior programmer with 20+ years of development experience, told me a set of methods 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 observation.

Problem source

We all know that there are a lot of read and write operations when Xcode is running or compiling. For example, the call from the hard disk, we will do so:

Let image = UIImage (named: "imageName")

At this time, Xcode will go to the computer’s hard disk to find pictures, read and write operations. Similar operations and access to documents, etc.. 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. Even more unfortunate is sometimes encountered hard disk failure and other issues.

Solving ideas

The so-called “where need to optimize, where the need for programmers”, Jeff at this time as a white knight debut. Years of computer research have made him very familiar with the whole computer architecture. The following diagram shows the computer structure.

Schematic diagram of How to make Xcode in reading and writing speed 100 times?

This diagram illustrates the basic architecture of the 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.

Come back to see our question: Xcode is now running in RAM, and then read and write data to the Storage, then the data back to RAM. There are two bottlenecks in this way:

  • Storage slow. Even the most advanced SSD, its speed is 400 times slower than RAM. That is, no matter how you optimize the software layer, its speed can not break through the bottleneck of SSD;
  • Data to be transmitted between the various modules. There is also a delay in the transmission process and unnecessary time consumption.

In response to these two bottlenecks, Jeff believes that if we can make all the read and write operations are done in memory (RAM), then it must be able to significantly improve the efficiency of Xcode. The question is, how?

Implementation method

The idea of the method is very simple, can be divided into two steps:

  1. Configure RAM. In the memory of a special open let Xcode use.
  2. Connect Xcode. Allow Xcode to connect to our exclusive memory space.

Here is the time to witness the miracle.

The first step is to create a.Sh file. The code is as follows.

#! /bin/bash RAMDISK= SIZE=1024 #size in "ramdisk" MB for ramdisk. diskutil erasevolume HFS+ $RAMDISK / `hdiutil attach -nomount ram://$[SIZE*2048]`

The second step, run the.Sh file. Knock on the command line.

How to make Xcode in reading and writing speed 100 times?

Then you will find that you will be more than one called ramdisk memory space, about 1 GB size.

How to make Xcode in reading and writing speed 100 times?

The third step, connect Xcode. Xcode -> Preferences -> Locations -> Locations Tab, configuration DerivedData.

How to make Xcode in reading and writing speed 100 times?

Advanced… Also be configured as shown below

How to make Xcode in reading and writing speed 100 times?

These are the steps. At this point you can enjoy the development of flying. Now all the files in the Project are in memory, compared to SSD, in theory is to be on an order of magnitude.

Matters needing attention

  • Allocate memory space. I have allocated 1GB of memory here when the hard drive, because my computer itself has 16GB memory space. If your computer memory is only 4GB, I do not recommend that you use this method, or suggested to allocate only 256M space to Xcode. In short, pay attention to the lack of memory or overflow.
  • Just put DerivedData in Ram Disk. In order to limit speed, of course, you can put all the relevant documents in the App memory space. But you know, we created the Ram Disk is essentially memory, when the shutdown or restart, the data in the Ram Disk will be lost. The DerivedData can be re generated, so the Ram can be placed in the Xcode to maximize the speed of reading in the development of Disk, and very safe.

Reference resources

  • Performance Considerations macOS/iOS Development the in New for Frontier”
  • Cache In Pocket: Use RAM disk for Your a Xcode