exponea / exponea-ios-sdk

MIT License
19 stars 27 forks source link

DatabaseManager waits on main queue #15

Closed sjavora closed 3 years ago

sjavora commented 4 years ago

Just noticed this when profiling our app - DatabaseManager.swift uses the context property for interacting with Core Data. This is defined as persistentContainer.viewContext. This means that context is associated with the main queue as described in the docs. All operations in DatabaseManager begin with context.performAndWait - perform and performAndWait run the block on the queue that the context is associated with... in this case, the main queue.

Since performAndWait is run synchronously on the context's queue, the main queue is blocked while DatabaseManager methods are run. This results in our app freezing when the database manager decides to do something.

As far as I know, there is nothing the app can do about this. Please let me know if my analysis is wrong, but I can't find anything else in the time profiler to explain this.

wassil commented 4 years ago

Yup, that makes sense. The SDK had issues with thread safety so switching to background thread seemed a bit crazy, but those issues were fixed a couple of versions back and this slipped. I'll add it to our backlog, with current state it should be an easy fix.

Thanks for the report!

wassil commented 3 years ago

Just released version 2.8.0 where DatabaseManager uses background context. This should be resolved, thanks again for reporting!