Animation Hitches in iOS Development
Make using your app delight by being aware of render loop
Hitch is a kind of performance issue where user feels rough while interacting with application. It may occur while scrolling, animation or transition between screens.
iPhone or iPad is having 60Hz refresh rate. Frame duration is 16.67 ms(1/60). When user starts interacting with the app, the new corresponding frames need to be rendered. This cycle of rendering new frames on to screen is “Render Loop”.
This Render Loop comprises of 5 stages as shown in above image.
Events are touches, keyboard presses or timers. Responding to these changes App View Hierarchy will be altered.
Changes corresponding to event from each view will be collected in next commit phase. These changes such as drawing image views or adding labels are applied to views from top to bottom and left to right. These collected changes were passed to Render Server.
In Render Prepare Phase the collected changes are pipelined in the order of top to bottom, left to right and back to front(layers).
Render Server executes this changes in next phase and displays them within a deadline. If any changes happened to miss the deadline causes the Hitches.
Hitches can occur in two stages of Render Loop
When commit phase takes extra time to prepare changes then Hitch occurred is Commit Hitch. Developer Tool Instruments from Xcode12 includes Animation Hitches measure. This also includes Time Profiler to detect and locate commit hitches.
When execution of pipeline takes extra time then Hitch occurred is Render Hitch. Same Instruments can be used to detect the Render Hitches labeled as “Expensive Gpu” hitch type. To fix them Xcode View Debugger is to be used. Xcode introduces performance optimizations to suggest fixes for render hitches. Those can be viewed by enabling Show Performance Optimizations from Editor menu.
To Learn More about each hitch and fixes to solve them see Apple Developer Talks.
Thanks For Reading !!!