Start a new topic

Some part of KCSCachedStore query runs on main thread

I am trying to use KCSCachedStore, but am having issues with some part of the query (before the completion block) running on the main thread, resulting in the UI freezing for a considerable amount of time.


When I simply change my store from

```

var LogbookStore = KCSCachedStore.storeWithOptions([

 KCSStoreKeyCollectionName : "entries",

 KCSStoreKeyCollectionTemplateClass : Entry.self,

 KCSStoreKeyCachePolicy : KCSCachePolicy.NetworkFirst.rawValue,

 KCSStoreKeyOfflineUpdateEnabled : true

 ])

```

to

```

var LogbookStore = KCSAppdataStore.storeWithOptions([

KCSStoreKeyCollectionName : "entries",

KCSStoreKeyCollectionTemplateClass : Entry.self,

 ])

```

I no longer have the issue.


Any advice on how to dig into this? I'm also noticing that the query takes about 1 second to reach the completion block when the data store is a KCSAppdataStore, versus 6 seconds when the data store is a KCSCachedStore (it's a decent enough amount of data that these times do not surprise me, it's the large difference (even when I'm not trying to run anything else on the main thread that is surprising.)


1 person has this question

Hi Diego,


Attached is a file with a unit test where we tried to reproduce the issue but couldn't, using the newest version of the iOS library are you still experiencing this issue?


Thanks,


1 person likes this
Diego, 

We are currently looking into why this is causing blocking in the main thread and should know more sometime in the near future. That said, you may be able to increase your performance by changing NetworkFirst to LocalFirst in your caching policy (if that works for you). Thanks for bringing this to our attention. 

Enjoy your afternoon.

1 person likes this

Hi! Just wondering what the status with this is? Were you able to recreate this problem?

Diego, 


We are generally pretty quick about getting this sort of thing patched and updated, so making a workaround may not be necessary.  I'd anticipate a fix for this in 1-2 weeks time based on past experiences.   It may be slightly more or less.


Great work guys! As of 1.33 this is no longer an issue.


The profiling I did before this fix suggests:

"

Improvement: Some methods in KCSBackgroundAppdataStore were running in the main thread and now are running in a separate queue.

"


Was what fixed it. Thanks so much!



Hello there Diego,


Can you please let me know which version of the iOS library you're running?  An issue that was very similar to this was addressed in version 1.3.0 of the library (released Apr 10, 2015 -- available here http://devcenter.kinvey.com/ios/downloads ).


Thanks,

Looks like 1.31.1


2015-05-28 13:55:58.225 GocapiOS[4130:819629] Kinvey iOS Library Version 1.31.1

Thanks!


I'll be keeping an eye on this, since I don't believe it is possible to pull data from kinvey using a KCSCached store without blocking the main thread, which means I'll have to make a workaround that can still use the nice offline save stuff this object allows (could get awkward?)