## Program optimization

  • Static analysis
    1. Xcode static analysis proudct-analyze
    2. Automatic static typing Build Settings Analyze During ‘Build’ is enabled for YSE
  • Leaks Allocation panels for MLeaksFinder, a dynamic detection tool, and Xcode’s built-in tool Instruments show which objects are “created and still in memory” and which are the most memory hogs. Level 1 memory warning Received Use this tool to view memory usage. The details show which class, which line of code creates, uses, and processes these objects. If EXEC_BAD_ACCESS appears, you can use the Allocation tool to locate the specific crash code.
  • Destruct each object and write some classified objects to delloc method

## Performance detection tool

  • The worst-case scenario for CPU usage is when the CPU has so many tasks to handle (such as user input, reading and writing files, network interaction) that the CPU should not have idle time. You must use multithreading to get the most out of your CPU. Instrument Sampler panel This tool can be used to sample at a fixed frequency; The default frequency is 10ms, but you can change this value. The tool records the CPU each time it is sampled. These records and samples are usually enough to identify performance bottlenecks and fix them.

  • Battery loss Run-profile-instrument Enable Energy Diagnostics

  • CoreAnimation detects how many frames your UI thread can render per second. The UI thread is also the main thread you need to consider in terms of detecting user interactions; It can only be tested on a real machine. Where is the problem code not determined

  • Color Blended Layer Making your view opaque will make rendering work faster because the GPU doesn’t have to do a second rendering at the same point. Opaque: green transparent: red

  • [UIImage imageNamed:@””] [UIImage imageNamed:@””] [UIImage imageNamed:@””] The imageNamed method does one important thing: it caches the loaded image in memory, and when you call the image again, you can reuse it directly from memory. It can only load images that are already in the source code. [[UIImage alloc] initWithContentsOfFile:@””] or [[UIImage Alloc] initWithData:Data] operating systems do not automatically cache operations in memory.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *CellIdentifier = @"CellIdentifier"; 
	ReuseTableViewCell *cell = (ReuseTableViewCell *) [self getCellWithTableView:tableView cellIdentifier:CellIdentifier nibName:@"ReuseTableViewCell"];
	NSString *avatarFile = [NSString stringWithFormat:@"a0"];
	NSString *avatarName = [[NSBundle mainBundle] pathForResource:avatarFile ofType:@"jpeg"]; cell.avatar.image = [self imageWithName:avatarName];
	cell.userName.text = [NSString stringWithFormat:@"hi here: %d", indexPath.row]; // Configure the cell. returncell; } // get image from dictionary - (UIImage *)imageWithName:(NSString *)name {if ([self.imageDictionary objectForKey:name]) { 
		return [self.imageDictionary objectForKey:name]; 
	}
	
	UIImage *image = [[UIImage alloc] initWithContentsOfFile:name]; [self.imageDictionary setObject:image forKey:name];
	return image;
}

Copy the code

If you wait too long, the UI rendering process will be blocked; Apps can’t display new content or do anything else. This is one of the reasons why users see scrolling forever stuck in one place.

	- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Initialize and return the Cell here
}
Copy the code