“This is my 10th day of the November Gwen Challenge.The final text challenge in 2021”

Abstract

Recently, when we contacted customers, they wanted to provide SDK performance, memory, privacy support and other data, so we conducted some performance tests on SDK.

While compiling this data with tabular statistics, it suddenly seemed like a good way to find optimizations was to look at SDK data in a statistical way often.

So I want to record the format of the statistics table, test tools and so on, so that I can optimize the SDK later.

SDK data table

First, sort out the performance and memory-related data in the SDK, and make the table as shown in the following figure for convenient statistics and viewing.

Next, follow each item in the table to get.

The performance data

CPU consumption and memory consumption, both of which can be obtained directly from Xcode. Once the program is running, switch to this panel as shown in the following image to see real-time CPU and memory consumption values. Here we get the maximum value of each of them.

CPU consumption

The interesting data here is the CPU. See the scale of CPU can be up to 600%, why so large?

Since the phone I’m using is the iPhone 12Pro, it has 6 cpus, so its maximum CPU is 6 cpus at full load, which is 600%. So you need to divide the value by 6 to get the true CPU consumption.

Different devices are used to obtain CPU, and different values can be obtained in the panel in the figure above. Therefore, the values in the panel can not be directly calculated on other devices, for example, the CPU consumption ratio of iPhone 7 cannot be directly divided by 2.

Memory consumption

Memory consumption is the maximum memory consumption obtained after running the entire SDK function. Remember to subtract the initial memory consumption, which is the memory consumption when you don’t run the features in the SDK.

After the APP is started, it will also need memory consumption, which is to maintain the normal operation of the APP. When the SDK functions are used, its memory consumption will be increased on this basis.

FPS (Frames Per Second)

FPS is defined in the graphics world as the number of frames per second that an image transmits. The more frames per second, the smoother the action. In general, the minimum to avoid unstructured action is 30.

FPS can also be referred to as “refresh rate” (in Hz). For example, a refresh rate of 75 Hz means that the screen scans only 75 times per second (75 frames per second).

Monitoring the FPS

Apple offers CADisplayLink class for FPS monitoring. CADisplayLink can create a timing object that allows an application to synchronize a drawing with the refresh rate of the display.

Here is the relevant code:

import UIKit class FPSLabel: UILabel { private var link:CADisplayLink? Private var lastTime:TimeInterval = 0.0; private var count:Int = 0; Override init(frame: CGRect) {super.init(frame: frame) //receiver refers to didTick method link = cadisplaylink. init(target: self, selector: #selector(fpslabel.didtick (link:)) //commom will print FPS whenever the user's app stops or slides. .add(to: RunLoop.current, forMode: .common) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @objc func didTick(link:CADisplayLink) { if lastTime == 0 { lastTime = link.timestamp return } // This is used to count how many times the method is entered in a second. If 20 times is entered, count becomes 20. 20 frames count += 1 // Let delta = link.timestamp - lastTime if delta < 1{ Return} // It is already one second, we will update lastTime to the current time for the next calculation lastTime = link.timestamp //delta is 1.0000000.... print("delta :(delta)") let fps = Double(count)/delta count = 0 text = String.init(format: "%02.0f frame ", round(FPS) print(text?? "0")}}Copy the code

Compatible with

Compatibility items are easy to obtain, starting with the lowest system version that the SDK can run, which can be set up in the project and can be easily obtained. The other is equipment, which covers a wide range of devices, such as mobile devices, iPad, iWatch or other devices. This will be handled according to the project.

Loading time

Here we use the comparison method to get the load time, i.e. run the load time without Framework, then run the load time with Framework, and make the difference (the method is relatively easy).

Within the project, select Edit Scheme.. Option, then set DYLD_PRINT_STATISTICS to 1 in the Run option.

This data is then displayed in the printed workbench each time the project is run:

Total pre-main time: 242.05 milliseconds (100.0%) Dylib loading time: 151.75milliseconds (62.6%) Rebase 22.21 milliseconds (9.1%) ObjC Setup Time: 6.99 milliseconds (2.8%) Initializer time: 71.09 milliseconds (16.2%) vs intializers: 7.70 milliseconds (3.1%) libBacktraceRecording. Dylib: 8.65 milliseconds (3.5%) libMainThreadChecker. Dylib: 40.24 milliseconds (16.6%).Copy the code

When you do the calculation, you just look at the time of the first term, and the other choices are useful for other purposes, so I’m not going to go into that.

Installation package size

The values of the installation package size reference can be viewed on the appStore distribution platform. Basically see installation size this index is ok. The installation size is the amount of memory used to install the application on the device.

The Framework installation size is obtained by uploading an empty application first, and then uploading an application with the Framework, and comparing the installation size of the Framwork package. Don’t look at the.ipa package file by looking at something that seems to be straightforward and quick. The data is very unreal and has no real reference value.

Privacy rights

The privacy permission is divided into two parts. One is the device permission to be used in the SDK. For example, the permission to take photos by camera should be set in the project. Another is the privacy aspect of showing up for use in the App Store. These two parts should be given to the recipient, so as not to affect the application online approval due to the lack of necessary privacy Settings.