1. Optimize the interrupt time before missing page (the first installation)

23. If so, remove the -fsanitize-coverage=func,trace-pc-guard configuration.

Delete app, clear Xcode cache;

Xcode menu bar > Product > Profile (Command +I), wait for running to complete;

When the Instruments screen appears, select System Trace;

Start the project, stop when the first screen appears, wait for analysis,

Search Main Thread, select Virtu Memory, check the number and time of File Backed Page in;

2. Get all function symbols loaded at startup

Remove the app, in Xcode Build Settings > Apple Clang-Custom Compiler Flags > Other C Flags

Add – fsanitize – coverage = func, trace – PC – guard,

Add the following code to the first screen that will appear after startup:

#import <libkern/ osatomic.h > #import <libkern/ osatomic.h > #import <libkern/ osatomic.h > // static osqueueHead symboList = OS_ATOMIC_QUEUE_INIT; Typedef struct {void * PC; void * next; } SymbolNode; void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) { static uint64_t N; // Counter for the guards. if (start == stop || *start) return; // Initialize only once. printf("[clang] INIT: %p %p\n", start, stop); for (uint32_t *x = start; x < stop; x++) *x = ++N; // Guards should start from 1. } void __sanitizer_cov_trace_pc_guard(uint32_t *guard) { //if (! *guard) return; // Duplicate the guard check. void *PC = __builtin_return_address(0); SymbolNode * node = malloc(sizeof(SymbolNode)); *node = (SymbolNode){PC,NULL}; OsAtomicenQueue (&symboList, node, offsetof(SymbolNode, next)); } void tmpOrderFile() { NSMutableArray<NSString *> * symbolNames = [NSMutableArray array]; SymbolNode * node = osAtomicDQueue (& Symbolist, Symbolist, Symbolist, Symbolist); offsetof(SymbolNode, next)); if (node == NULL) break; Dl_info info; dladdr(node->pc, &info); NSString * name = @(info.dli_sname); / / add _ BOOL isObjc = [name hasPrefix: @ "+ ["] | | [name hasPrefix: @" - ["]; nsstrings * symbolName = isObjc? Name: [@ "_" stringByAppendingString: name]; / / to weigh the if (! [symbolNames containsObject: symbolName]) {[symbolNames NSString * thisFunc = [NSString String WithFormat:@"_%s", __Function__]; if ([SymbolNames containsObject:thisFunc]) {[SymbolNames removeObject:thisFunc]; [NSMutableArray arrayWithArray:[[symbolNames reverseObjectEnumerator] allObjects]]; NSLog(@"[clang] %@",symbolAry); / / the result written to the file nsstrings * funcString = [symbolAry componentsJoinedByString: @ "\ n"); nsstrings * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"lb.order"]; NSData * fileContents = [funcString dataUsingEncoding:NSUTF8StringEncoding]; BOOL result = [[NSFileManager defaultManager] createFileAtPath:filePath Contents :fileContents Attributes :nil]; if (result) {NSLog(@"[clang] %@",filePath);}else{NSLog(@"[clang] %@");}}

Then call tmPorderFile () from viewDidAppear (or from any other event method).

After the first screen appears (or another event method fires and completes), download the file.

Right-click “Show Package Contents” for the downloaded file and find the lb.order file under the TMP file, which contains all the bullet points that were loaded.

3. Rearrange the startup symbol

Copy the LD. Order file to the project directory;

Search for the order file in the Build Setting and write the path to the ld.order file:

Repeat step 1 to see the optimized result.

View symbol reorder

In the Build Setting, search the link map, change the Write link map File to YES, and go to the intermediates.noindex directory of Products’ Intermediates… Build _ios.build file, search # Symbols:, which is the order in which the project is compiled, and compare it with LD.

4. Time of page short interrupt after optimization

The project is well planned, so there is not much room for optimization.

The interrupt speed of missing pages increased by 32.44%; The overall speed increased by 46.34ms and 29.32%.