How can I make CSSearchableIndex indexSearchableItems faster

I'm using [CSSearchableIndex defaultSearchableIndex] indexSearchableItems: to index my app's content with Core Spotlight.


I'm having problems related to performance, our app has about 600 individual, searchable content items which we need to index. The first time the app launches, we begin to index them, one at a time. For each item of our content, we have to first download the content's thumbnail image from our server (which goes in CSSearchableItemAttributeSet thumbnailImage property).


I've considered using beginIndexBatch/

endIndexBatchWithClientState
as a way of speeding things up, but I am reluctant because of the thumbnail image. In order to batch-index all the content, I would need to first download the thumbnail images for every content item, which is an All or Nothing proposition.

If I index the content one item at a time, my belief is, the user will be able to find some content in Spotlight right away, if not all. If I wait until every thumbnail image is downloaded first, it will be many minutes before ANY content is indexed, and if the user closes the app, it will never finish. My belief is that by indexing the content one at a time, I create a set of searchable content earlier.

But, all of this could be avoided if I could index the content WITHOUT having to first download the thumbnail image. But, I cant find any way to set the thumbnnail image URL so I could pass that instead (presumably to let the OS download the image in the background outside ofthe App's execution space).

Now, there is a property called "thumbnailURL" in the CSSearchableItemAttributeSet object. However, the documentation states this is "The local file URL of the thumbnail image..." - so obviously I cannot put a URL here which links to a file on my server, it has to be an image already downloaded (and saved to the local file system).

So, it appears there is no way to avoid downloading the thumbnail images, in which case, I feel I need to use one-by-one indexing. I would love to know what other people are doing in this scenario, and how it might be possible to speed up the indexing process. There are 2 pain points in the process, a) downloading the image, which there is no way to speed up, b) Calling [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems.

I suppose absent any feedback from someone with real world experience doing this, I might try next to use beginIndexBatch/

endIndexBatchWithClientState
but, not try to process ALL the content in one batch, instead maybe process a dozen at a time or so. That would probably be a good middle ground.

Any advice? Thanks in advance.

not try to process ALL the content in one batch, instead maybe process a dozen at a time or so.

That’s what I’d do.

I’d also take a look at how your thumbnail download code is using the network. If you have code like this:

  1. Start the next download

  2. Once it’s finished, go back to step 1

you’re likely to be suffering from latency issues. It’s critical that you present enough downloads to the networking stack to hide that latency, and thus use the available bandwidth.

Note If you’re not familiar with the importance of latency in networking, it’s something I discussed in my WWDC 2010 presentation, Network Apps for iPhone OS. It’s too old to link to directly, but you can find both parts in the archive.

Finally, take a look at WWDC 2017 Session 231 What’s New in Core Spotlight for iOS and macOS, which has a whole bunch of useful hints and tips on indexing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How can I make CSSearchableIndex indexSearchableItems faster
 
 
Q