0xc00010ff/UIView-SequentialAnimation

Scheduling loses precision after many iterations

Closed this issue · 1 comments

I'm opening this issue as a reminder to myself to implement the fix for this that I've already used in my production application.
Problem:
In a sequential animation with around ~50 views, the operations inside the animation blocks suddenly begin to happen at the same time. As in, the 51st and 52nd animation block will be executed at the same time.
Explanation:
After a lot of confusion- I found that GCD (the automated thread pooling tool used in Cocoa development) heavily uses timer coalescing (http://en.wikipedia.org/wiki/Timer_coalescing) to minimize cpu load. By default, GCD allows a pretty big window of discrepancy for scheduled tasks- what seems to be about 10% of however long the requested delay is for that task. Judging by the fact that the a sequential animation operation begins to lose precision more as time continues, I would guess that GCD begins to up the time discrepancy window the longer one of its worker threads stays busy.
The fix for this is to make our own GCD timer with a discrepancy or 'leeway' value of 0, so the animations will always fire on time. Presuming the animations do not involve very time consuming calculations at every iteration, this should not cause any performance issues. It seems to be doing it's job correctly and quietly in my other apps.
Will update soon after thorough testing.