Since iOS 8 was released we’ve noticed some sluggishness when using Flipboard in the simulator. When taking a trace with Instruments in normal use we noticed a significant amount of time was being spent in
.1
CFPreferences
On Twitter, an Apple engineer acknowledged that there were some changes in iOS 8 that added something called
, and that emulating that in the simulator required synchronous reads from disk. This seemed to be the bottleneck we were encountering.1
cfprefsd
@timonus unfortunately cfprefsd doesn’t currently exist in the simulator, and emulating its behavior requires synchronize disk IO
— David Smith (@Catfish_Man) January 21, 2015
@timonus it’s on my list to fix, but it’s a large effort and device took priority
— David Smith (@Catfish_Man) January 21, 2015
About a month ago we were talking as a team about how slow we felt our app had become to debug in the simulator, so we decided to try to do something to speed it up. Our approach was to introduce a man-in-the-middle write-through cache to
in memory. We do so by swizzling out all of 1
NSUserDefaults
’ setters and getters and adding a per-instance 1
NSUserDefaults
to cache values. We avoid compiling this for device builds using 1
NSMutableDictionary
because there aren’t such performance issues on device. The increase in performance is dramatic, where we were once spending 80% of our time in 1
TARGET_IPHONE_SIMULATOR
we’re now spending 1%.1
CFPreferences
If you’re seeing performance issues related to
in the simulator I recommend trying this out, it’s open source and available for download on GitHub. To get started using it all you need to do is include it in your project.1
NSUserDefaults
Please note that use of this category may cause side effects when debugging extensions. This is documented in the GitHub project.