摘要:iOS 应用,丝般顺滑的理想情况就是 60FPS (对于 iPad Pro 是 240FPS),即在 16ms 之内完成一次渲染。如果找到在每次渲染花费了多久,究竟做了什么事情,那么就可以进行针对性的优化。 RunLoop 的概念在程序中,我们需要一种机制,可以让当前线程能够随时处理事件但不退出。这种模型通常被称为 Event Loop,在 iOS 中使用 RunLoop 来实现。RunLoop...
阅读全文
摘要:话不多说,先上代码,在分析Code- (void)viewDidLoad { [super viewDidLoad]; dispatch_group_t group1 = dispatch_group_create(); dispatch_group_t group2 = dispatch_group_create(); NSLog(@"1,begin"); if (...
阅读全文
摘要:先来几个同义词readers–writer (RW) lockshared - exclusive lockmultiple readers/single-writer lockmulti-reader lock push lock解决的问题允许多个线程同时读取数据。只允许一个线程写或更新数据写数据时,其他的写操作和读操作要被阻塞。(SQLite 的 WAL 不是,允许同时读写)实现时需要考虑的问...
阅读全文
摘要:条件变量是一种同步机制,允许线程挂起,直到共享数据上的某些条件得到满足。条件变量上的基本操作有:触发条件(当条件变为 true 时);等待条件,挂起线程直到其他线程触发条件 while ()为什么是while而不是if?因为可能会有虚假唤醒的问题。 "This means that when you wait on a condition variable, the wait may (o...
阅读全文
摘要:“undefined behavior: behavior for which this International Standard imposes no requirements.” example of Undefined BehaviorUse of an uninitialized variableMisaligned pointers Access to an object...
阅读全文
摘要:要用 release 版本来profile 概述time profile 是使用采样的方法来统计,而不是记录每一个方法调用的起始和结束,采样间隔是 1 ms。 在上图中,main 函数被采样了 5 次, method3 没有被采样,但是确实执行了。不能区分长时间运行的任务和重复执行的任务。关注点是 CPU,而且不会记录所有操作。比如 method3 没有被采样。 如何看 time profi...
阅读全文
摘要:原理使用 system trace 时,会记录最近 5s 的 kernel trace,然后分析下面的操作: Scheduling activity System calls Virtual memory operations使用在代码里插入相应的语句,当运行到这里是,会在 Instrument 的结果中。插入的语句可以指明一个事件的发生,或者一个时间段的起始和结束。其中第一个参数指定事件的 ...
阅读全文