Прочитайте call tree в Instruments Time Profiler и найдите hot path
Вы профилировали лагающий скролл ленты инструментом Time Profiler. Ниже call tree, взвешенный по total time, а во втором столбце — self time каждого фрейма.
Прочитайте его так, как в Instruments — инвертируйте дерево, спрячьте системные библиотеки и сфокусируйтесь на главном потоке — и назовите настоящий hot path в своём коде.
Weight Self Symbol
99.1% 0.0% Main Thread 0x1d3a
98.7% 0.1% start
98.5% 0.2% UIApplicationMain
71.4% 0.3% -[FeedCell configure:] MyApp
70.9% 61.8% -[FeedCell buildAttributedText:] MyApp
27.0% 26.4% CA::render::commit QuartzCore
5.2% 5.0% applyImageDecode ImageIO
Объясните, как вы находите hot path.
Инвертируйте call tree, чтобы тяжёлые по self time листья поднялись наверх, спрячьте системные библиотеки, и сфокусируйтесь на главном потоке. У start большой total, но ~0 self. Hot path — это -[FeedCell buildAttributedText:] с ~62% self.
- ✗Читают верхний фрейм по total time вместо инверсии ради self time
- ✗Оставляют системные библиотеки видимыми и винят фреймворковый фрейм
- ✗Принимают большой total time за стоимость вместо большого self time
- →Почему у
startбольшой total time, но почти нулевой self time? - →Когда системные библиотеки стоит оставить видимыми, а не прятать?
The inverted tree, with system libraries hidden, collapses the deep start → UIApplicationMain spine (high total, ~0 self) and surfaces the frame that actually burns CPU:
Self Symbol
61.8% -[FeedCell buildAttributedText:] MyApp ← hot path
26.4% CA::render::commit QuartzCore (hidden as a system frame)
5.0% applyImageDecode ImageIO (hidden as a system frame)
Total time (Weight) tells you which subtree the samples fell under; self time tells you where the CPU was when sampled. start and UIApplicationMain sit at ~99% total but ~0% self — they only contain the work. Once system frames are hidden, the only frame you own with large self time is -[FeedCell buildAttributedText:] at ~62%. That is the hot path: attributed-string building on the main thread during scroll. Move it off the main thread or cache the result.