I have a pretty simple cocoa app (NOT iphone) that consists of a single WebView instance that covers the entire app window. I've noticed that on certain pages the app will consume 100% of one of the cores. Using Instruments I can see that almost all of the time is spent in [NSView displayIfNeeded]. Drilling down through the call tree leads to [WebHTMLView drawSingleRect]. The same page running in Safari works fine with almost no CPU usage...
Anyone have any ideas why this would be?
Additional info:
- If I resize the app window (even by a tiny amount) the CPU usage drops back down.
- Running OS X 10.8.5
EDIT: The only 'fix' I've found is to add an NSTimer resizes the window. If anyone knows what happens during a resize that would 'fix' the issue I'd love to hear it.
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(resizeToFixCPUUsage) userInfo:nil repeats:YES];
- (void)resizeToFixCPUUsage {
NSRect frame = [self.window frame];
frame.size.height -= 1;
[self.window setFrame:frame display:NO animate:NO];
frame.size.height += 1;
[self.window setFrame:frame display:NO animate:NO];
}
Instruments showing CPU usage:
Web Inspector showing paint (app uses 100% CPU matching the solid purple bar):