I am teaching myself a little about concurrency using GCD. I made good progress and was able to greatly improve app responsiveness. I noted when running apps on El Capitan there was a tremendous slow down. I experimented and developed a very simple sample code that shows a 400 times difference in execution speed between OS 10.11 and OS 10.10.
The test code is very simple - creates a dispatch queue that submits three jobs:
1) Record the start time
2) Run a simple loop and update an NSSlider
3) Print the total time of execution.
When updating the interface, I use "dispatch_sync(dispatch_get_main_queue() ... " to ensure my interface calls are executed on the main queue. I use sync to ensure that update of the interface element is smooth.
Here is the weird thing, when executing the sample code below El Capitan is PAINFULLY slow.
10.11 Execution Time: 16.6 seconds
10.10 Execution Time: 0.04 seconds
Nearly 17 seconds to loop though only 1000 times!!!!
If I use "dispatch_async" for the main queue calls (line 21) both 10.11 and 10.10 execute the code in 0.002 seconds - however, for longer loops the display is not smooth - I need to use sync to get the desired effect.
Is this a known issue with El Capitan? I have not seen any reference to this, but have notice that people are having issues with iOS 9 that could be related to this.
Thanks.
class ViewController: NSViewController {
@IBOutlet weak var slider: NSSlider!
let limit = 1000
var startTime: NSDate!
let serialQueue = dispatch_queue_create("serialQueue", nil)
override func viewDidLoad() {
super.viewDidLoad()
self.slider.integerValue = 0
self.slider.maxValue = Double(limit)
}
@IBAction func start(sender: AnyObject) {
dispatch_async(serialQueue, { self.startTime = NSDate() } )
dispatch_async(serialQueue, { self.rampUp() } )
dispatch_async(serialQueue, { print(self.startTime.timeIntervalSinceNow) } )
}
func rampUp() {
for i in 0...self.limit {
dispatch_sync(dispatch_get_main_queue(), {
self.slider.integerValue = i
})
}
}
}