I realized that I was queuing a lot of blocks calling to empty methods. In the debugger it looks like a lot is happening when really all the blocks are empty.
Is there any real performance impact from having empty blocks?
The overhead should be negligible: You may check this with Instruments and a simple program like:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
void (^b)(void) = ^{ };
double d = 2.0;
for(int i = 0; i < 10000000; ++i) {
dispatch_sync(q, b);
d = d * 1.5 - 1.0;
}
NSLog(@"d = %.3f", d);
}
return 0;
}
As you can see in the Instruments stack trace the calls require 40ms for 10 millions synchronous invocations of an empty block. That's not much overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With