This is not strictly Swift-related, but priority inversion has been such a topic during the design of Swift Concurrency, and I wanted to thank someone.
You don't quite know what "priority inversion" is, how to recognize it, how to fix it? I bet you're not alone.
Rejoice: Xcode 14 beta ships with a new diagnostic tool that emits purple runtime warnings when our apps misuse their threads, and have a high-priority thread wait on a low-priority thread:
The Thread Performance Checker is enabled in the scheme editor:
I just met a real-life example: in GRDB, an SQLite database runs on a DispatchQueue whose default quality of service is DispatchQoS.default
. The Thread Performance Checker was able to diagnose that performing a synchronous database access from the main thread was a case of priority inversion. The runtime warning can be removed by granting SQLite a .userInitiated
qos, or by removing all sync accesses from the main thread.
If the people responsible for this feature are reading this forum, please be assured your work is noticed, and warmly welcome