0

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: Instruments showing CPU usage

Web Inspector showing paint (app uses 100% CPU matching the solid purple bar): Web Inspector showing Paint

danw
  • 1,528
  • 1
  • 17
  • 17
  • Can you post some simple example code reproducing this issue? Does it only occur with a single URL or multiple URLs? Hard to diagnose without any more information. – tjarratt Oct 11 '13 at 06:03
  • Have you tried [opening the page in the Web Inspector in your app](http://stackoverflow.com/a/16483200/30461) and seeing what the Timeline and Profile tabs say? – Peter Hosey Oct 11 '13 at 23:22
  • @PeterHosey thanks for the tip. It's showing consistent and repeated 'Paint' calls under 'Layout & Rendering'. When I resize the window slightly those stop... see: http://i.imgur.com/aV4qFJf.png – danw Oct 12 '13 at 00:49
  • Also, I notice that the 'Area' column shows massive numbers while it's using heaps of CPU, after resizing those numbers drop down to much smaller numbers (480000px^2 vs 57px^2). – danw Oct 12 '13 at 00:54

0 Answers0