Skip to content

Xcode 14 beta: Thread running at QOS_CLASS_USER_INTERACTIVE waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions #1234

@groue

Description

@groue

Thread running at QOS_CLASS_USER_INTERACTIVE waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions

This message can appear as a runtime warning (purple ⚠️ sign), in Xcode 14 beta, inside the internal GRDB.Pool.get() method:

final class Pool<T> {
    func get() throws -> (element: T, release: () -> Void) {
        try barrierQueue.sync {
            itemsSemaphore.wait() // <- ⚠️ Thread running at QOS_CLASS_USER_INTERACTIVE…

It happens when the application performs a synchronous database read, from the main thread, with DatabasePool.


To remove this warning, instruct the database to run with higher priority:

var configuration = Configuration()
// As we plan to access the database from the main thread, make
// sure it runs with an appropriate quality of service:
configuration.qos = .userInitiated
let dbPool = try DatabasePool(path: ..., configuration: configuration)

This warning is a new tool in Xcode 14 beta, the Thread Performance Checker. You enable it in Xcode > Edit Scheme… > Run > Diagnostics > Runtime API checking > check "Thread Performance Checker".

Thank you Apple for warning us that we misuse our threads :-)


We'll probably raise the default quality of service of GRDB databases in a future release. If we do not, many Xcode 14 users will start to see this runtime warning, and I don't want to ship a library that warns on first use:

  • I do not want to deal with the support requests this would create.
  • SQLite is very fast, simple apps ought to remain simple, and nobody should be shamed for accessing the db from the main thread.

Please feel free to comment below, if you think we can be more subtle than raising all databases to .userInitiated 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions