0

I'm using CocoaLibSpotify in my iPhone app. At one point the user has the option to search for artists/songs etc on Spotify. Once the search completes, a UITableView is populated with the search results. I've noticed that the app starts to lag a lot after performing a few searches. I started up the Activity Monitor in Instruments and noticed that CPU usage (% CPU in the Activity Monitor) climbs up to around 200% after performing a search. What's strange is, it sometimes takes up to 2 minutes to come back down to a normal level of about 6%. Here is the code I'm using to perform a search:

-(void)performSearch:(NSString *)searchString{

    if(!self.spotifySearch){
        self.spotifySearch = [SPSearch searchWithSearchQuery:searchString inSession:[SPSession sharedSession]];

        [SPAsyncLoading waitUntilLoaded:self.spotifySearch timeout:20.0 then:^(NSArray *loadedItems, NSArray *notLoadedItems){
            NSLog(@"Search completed");
            self.spotifySearch = nil;
        }];
    }
}

Obviously my search method isn't really doing much yet but simply running the above code multiple times causes a massive CPU load. Sometimes it also happens after running the code just once. My questions now are:

  1. Is there something I'm doing wrong?
  2. How can I run multiple SPSearches with different search strings? Is re-initializing the SPSearch object with SPSearch searchWithSearchQuery the proper way to do this?
  3. Is there a way to cancel a running search?

Any help is appreciated, thank you!

cbbcloud
  • 479
  • 5
  • 15

1 Answers1

0

Are you sure it's actually the search causing it? The playlist system is known to cause high CPU usage at times. Use Instruments to deduce the exact cause of the load and you'll be in a much better position to get it fixed.

There's nothing wrong with your approach. To cancel a search, simply release it and it'll go away. It's also fine to have multiple search instances running at the same time.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Hello. Thank you for your quick response. I've created a sample project that simply allows the user to search for things on spotify. It seems the lagging behavior isn't consistently reproduceable. Regardless I posted the sample project on google code. Maybe you could take a look at it? The code is here: svn checkout http://spotifysearchsample.googlecode.com/svn/trunk/ spotifysearchsample-read-only. Thanks again for the help. – cbbcloud Apr 21 '13 at 14:33
  • This seems to have resolved itself. I'm no longer able to reproduce this. – cbbcloud May 01 '13 at 17:33