Hangs with non-busy main thread using Instruments

Hi! I watched the 'Analyze hangs with Instruments' video from WWDC2023. It's such a great video! Unfortunately, I found a case that the video doesn't cover when profiling my browser app using Instruments:

As shown in the image, the hangs still occur even though my main thread is not busy, and I've also used the 'Thread State Trace instrument' to confirm that the main thread is not blocked either.

I'm not sure what the next step is to resolve the hangs. Any insight or guidance would be much appreciated. Thank you!"

Replies

Hi there,

happy to hear you found the WWDC session helpful!

Based on your screenshot it looks very much like a (mostly) blocked main thread. You mentioned that you also tried running with the "Thread State Trace" instrument. Would you have a screenshot of the thread states of the Main Thread during one of the hangs as well? If possible, also include what the "Narrative" detail view for the Main Thread shows for the time of the hang.

Hi!

Thank you so much for confirming it's a blocked main thread!

It turns out I was silly enough not to realize I need to toggle the Thread track button to see the Thread graph. So it IS a blocked main thread.

However, the Narrative view only shows one of my function causing the issue but doesn't specify which line is the cause. I've scratched my head for hours, but couldn't understand why. The function is basically reusing the WKWebView for using it in SwiftUI UIViewRepresentative, which should only use the main thread, isn't that it...? Is there a way to let the instrument tell us which line is causing the blocking?