Re:TheKitchenSync - A Tool Belt for iOS Concurrency
by asarazan on Tuesday May 14, 2013 @11:44AM
(#5705652)
I've been thinking about this since yesterday, and it seems like a really good solution for some use cases, but isn't there quite a bit of overhead to using a dispatche queue for fine-grained operations? I mean it seems like the overhead of cross-thread communication would severely outweigh a simple synchronous lock call.
Then again, if you can do things like background non-essential operations, then the higher-level benefits can probably outweigh that.
Re:TheKitchenSync - A Tool Belt for iOS Concurrency
by mikeash on Tuesday May 14, 2013 @12:04PM
(#5705810)
Like I said, GCD has a heavy emphasis on performance. For example, a dispatch_sync will involve no cross-thread communication in the uncontended case, and the cost is comparable to taking a spinlock. A bit heavier, but not too much.
dispatch_async will necessarily be slower, but don't overestimate how much work is really going to happen in the cases where it matters.
Its also very flexible, as you can do `dispatch_sync` if you need a synchronous fetch of the resource or use callback blocks to go as async as possible.