Re: GCD killed my performance
Re: GCD killed my performance
- Subject: Re: GCD killed my performance
- From: Jens Alfke <email@hidden>
- Date: Thu, 24 Apr 2014 20:47:51 -0700
On Apr 24, 2014, at 8:42 PM, Ken Thomases <email@hidden> wrote:
> You may be aware of this, but dispatch_sync() is not necessary or even particularly relevant to thread-safety. The use of a serial queue or, possibly, a reader/write mechanism using barriers, is what achieves thread safety.
Initial experimentation showed that dispatch_async was significantly slower than dispatch_sync. This makes sense because dispatch_async has to copy the block (thus allocating an object on the heap and retaining any captured object variables) while dispatch_sync can get away with running the block before the call returns, which avoids all that overhead.
> Using a synchronous call is only necessary if your API has synchronous semantics. For example, if a call provides immediate results to the caller. Reading from a database would typically have to be synchronous, but writing to it can often be asynchronous.
Yeah, I was torn about making the write calls async. But in the underlying C API both the read and write calls return error codes, since there could be disk or memory errors, and I didn’t want to ignore the return codes on the write functions. (My mama didn’t raise no boys to skip proper error handling.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden