Replies: 1 comment
-
Hello @crenelle, GRDB support for Swift Concurrency, precisely You do not share any information about the way you are "adding a background thread", so it is impossible to guess what's wrong in your application. Please consider checking the Concurrency guide. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using GRDB in a Swift/SwiftUI app since late 2019, and haven't been encountering any serious or wacky issues in that time (I think I asked about something in 2020). My app was simple, everything running in main and there were no issues to speak of.
Now I'm adding a background thread and having most of the database reads (there are no writes) and computations being done in that, in order to brighten up the UI. I have stuff like:
if (dbPool != nil) {
do {
try dbPool.read { db in
let expData = try Row.fetchOne(db, sql:query, arguments:[symbol, contractYear, contractMonth])
exp = toString(expData?["expiration"])
expRec["expiration"] = exp
let boundryData = try Row.fetchOne(db,
sql:"""
SELECT DATE(?,?) as cutoff_date
""",
arguments:[exp, sub8day]
)
...
moved to the background thread. This code seems to run fine for a while and then it starts to take up the majority of runtime. It seems to spend most of the time doing a DatabasePool.read(:) myapp in a closure running OS_dispatch_queue.sync(execute:) libswiftDispatch.dylib, and the second DatabasePool.read(:) myapp in a closure running SerializedDatabase.sync(_:) myapp. This looks like thrashing.
I'd normally stew over something like this for a while (days) before asking about it, but then I noticed that the async / await support in GRBD is labeled experimental. SInce I'm just now making some sense with GCD vs async / await, I thought maybe I'd better ask early.
I'm not currently seeing warnings about updating published from background (I was earlier).
Beta Was this translation helpful? Give feedback.
All reactions