I needed to display HTML text inside my iOS application. I decided to use the built-in NSAttributedString method, initWithData:options:documentAttributes:error: Actual parsing works just fine, however, it looks like I ran into a very strange error, which, apparently, only appears if I have a debugger.
The first time this method is called, it takes about 1 second and about 1.5 seconds on the 5th generation iPod Touch to run on my iPhone 5S running iOS 7.0.4. The quirk also appears on the simulator, but it is much less noticeable due to the sheer speed of the simulator.
Subsequent calls take about 10-50 ms, which is significantly faster than the initial call.
This is not like caching an input string, as I tested it with multiple input strings in my βrealβ application.
However, when I run the program without a debugger, it works as expected, about 10-20 ms, which I expect from HTML parsing.
Here is the relevant section of code:
-(void) benchmarkMe:(id)sender { NSData *data = [testString dataUsingEncoding:NSUTF8StringEncoding]; NSTimeInterval startTime = [[NSDate date] timeIntervalSinceReferenceDate];
Note A fully working project demonstrating this error can be found here:
https://github.com/richardjrossiii/NSAttributedStringHTMLBug
I've gone crazy? Is something missing here? 1 second is a very large amount of time when I try to optimize my application for performance.
My current solution is to parse the 'dummy' line when the application starts, but this seems like an incredible hacker solution.
ios objective-c cocoa-touch lldb nsattributedstring
Richard J. Ross III Jan 16 '14 at 16:01 2014-01-16 16:01
source share