пʼятниця, 25 березня 2011 р.

iOS blocks aka closures

iOS 4 blocks (Apple's closures) are awesome! Much more power for callback code and asynchronous execution. Though blocks require a bit more attention to memory management then function calls due to capturing calling method variables.

On the other hand, my tests with calling UIKit code adding 322 labels of 2 latin alphabet length each to the view controller yielded 3.5 seconds of execution on the main thread. Compare this with about 10 seconds of execution through dispatch_async call on the global queue with HIGH priority having nothing else added to this queue (iPhone 4 device). At his point more information required to compare blocks performance to exclusive thread execution. Or does it have something to do with non-thread-safety of UIKit?