My app is working well and I didn’t get this error on Xcode 13.4,
Is it Xcode 14 beta bug or I’m doing some bad threading?!
Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions
I didn’t understand the issue, so I added my stack log too:
_TtGC7SwiftUI14_UIHostingViewVVS_P10$1dc8d4d8821BridgedNavigationView8RootView_ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
2022-06-07 18:53:41.412342+0430 MyApp[916:25641] [UIFocus] _TtCC7SwiftUI17HostingScrollView22PlatformGroupContainer implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
Thread Performance Checker: Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversionsPID: 916, TID: 25815
Backtrace
=================================================================
3 MyApp 0x0000000102c7665c -[_FSRRunLoopThread runLoop] + 44
4 MyApp 0x0000000102c763a8 __45+[NSRunLoop(FSRWebSocket) FSR_networkRunLoop]_block_invoke + 124
5 libdispatch.dylib 0x00000001054318fc _dispatch_client_callout + 16
6 libdispatch.dylib 0x0000000105433240 _dispatch_once_callout + 80
7 MyApp 0x0000000102c76304 +[NSRunLoop(FSRWebSocket) FSR_networkRunLoop] + 84
8 MyApp 0x0000000102c6ff30 -[FSRWebSocket _connect] + 68
9 MyApp 0x0000000102c6ed60 -[FSRWebSocket open] + 216
10 MyApp 0x0000000102c4ebdc -[FWebSocketConnection open] + 248
11 MyApp 0x0000000102c4d3c4 -[FConnection open] + 112
12 MyApp 0x0000000102bf1404 -[FPersistentConnection openNetworkConnectionWithContext:] + 588
13 MyApp 0x0000000102bf1078 __45-[FPersistentConnection tryScheduleReconnect]_block_invoke_2 + 332
14 MyApp 0x0000000102c3d0fc -[FIRDatabaseConnectionContextProvider fetchContextForcingRefresh:withCallback:] + 264
15 MyApp 0x0000000102bf0f0c __45-[FPersistentConnection tryScheduleReconnect]_block_invoke + 460
16 MyApp 0x0000000102c1c0d8 -[FIRRetryHelperTask execute] + 92
17 MyApp 0x0000000102c1c6dc __24-[FIRRetryHelper retry:]_block_invoke + 84
18 libdispatch.dylib 0x00000001054300c4 _dispatch_call_block_and_release + 24
19 libdispatch.dylib 0x00000001054318fc _dispatch_client_callout + 16
20 libdispatch.dylib 0x0000000105438a58 _dispatch_lane_serial_drain + 688
21 libdispatch.dylib 0x00000001054396d0 _dispatch_lane_invoke + 424
22 libdispatch.dylib 0x0000000105445150 _dispatch_workloop_worker_thread + 696
23 libsystem_pthread.dylib 0x000000023db94ddc _pthread_wqthread + 284
24 libsystem_pthread.dylib 0x000000023db94908 start_wqthread + 8
4
Answers
You’re getting this message due to a priority inversion in your code. More details here: https://developer.apple.com/documentation/xcode/diagnosing-performance-issues-early
More specifically, you’re using
dispatch_group_wait
which doesn’t provide priority inversion avoidance; so your waiting thread is susceptible to an inversion. Seemingly that’s what’s happening here.this a bug in Xcode that’s mistakenly triggering warnings to be printed. This is not something that we can fix at the moment. Do bear in mind that these warnings are being sent mistakenly; the performance of your app will not be affected.
More information will help to understand this better but…
It looks like you are calling a FireBase class from a thread with a higher QOS than the one used by the class itself.
As Apple wrote in the Diagnosing performance issues early
"If you use concurrency primitives, such as dispatch_semaphore_wait and dispatch_group_wait, in your code or invoke APIs that use them, your app is susceptible to priority inversions if there is a mismatch in the quality-of-service (QoS) class of the dispatch queues your app uses."
In your case, you are calling the class from "QOS_CLASS_USER_INITIATED"
It is better to fully understand where you are calling it and why.
Since you do not have access to FireBase, you can try to resolve this issue by handling the QOS from the calling site like this:
For those coming here because they got the error in their own code, and not in Firebase, Firebase fixed the issue in version 9.6 by adding the line
when they created the thread. Presumably this increases the priority of the network thread so that it will avoid the priority inversion.