Cocoa WebView: boot time when the computer is idle

I wrote a simple Mac OS app. The view only contains the hidden WebView and NSTextView. At a certain time, 100 URLs will be parsed one by one. The url is loaded into the WebView, the DOM tree is parsed, gargled and repeated.

Everything works fine, except for some significant differences in boot times when the computer is idle (no user activity). When I use a computer, the URL takes about 2 seconds to load. When I am not using the computer for a while, the URL takes about 1 minute to load.

When I go back to my computer after a while and see in the TextView that the last URLs took about a minute, the next ones will immediately load in seconds. So it must be something with user activity on the system. Right? Does anyone know why?

I'm on OS X 10.9.4.

Here is the URL loading code:

#pragma mark -

- (void)processNextUrl
{
    // No url, stop
    if (_processQueue.count == 0)
        return;

    // Process url
    NSString     *urlString = [_processQueue objectAtIndex:0];
    NSURL        *url       = [NSURL URLWithString:urlString];
    NSURLRequest *request   = [NSURLRequest requestWithURL:url];

    [[_webView mainFrame] loadRequest:request];
}

#pragma mark - WebFrameLoadDelegate

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
    // Page ready for parsing?
    if ([[sender mainFrame] isEqual:frame] == NO)
        return;

    // Append date, time and url to TextView
    NSString *url = [[[[frame dataSource] request] URL] absoluteString];
    [self logText:url];

    // Parser does some DOM parsing and outputs to TextView
    Parser *parser = [[Parser alloc] initWithWebFrame:frame delegate:self];
    [parser parse];
}

#pragma mark - ParserDelegate Methods

- (void)parser:(Parser *)parser didFinishParsingUrl:(NSString *)url
{
    [_processQueue removeObjectAtIndex:0];
    [self processNextUrl];
}

      

+3


source to share


1 answer


I would bet AppNap is the start and starvation of your resource process.



You can disable AppNap in your app's Finder Get Info window - a temporary test to make sure I'm correct, or simply use NSProcessInfo beginActivityWithOptions: reason: to tell the system that the activity was initiated by the user and the app shouldn't be throttled.

0


source







All Articles