Search code examples
xcodeuikitthread-safety

Xcode hang risk warnings


I am puzzled by a deluge of warnings in Xcode 15 like:

This code path does I/O on the main thread underneath that can lead to UI responsiveness issues. Consider ways to optimize this code path

on code that seems perfectly innocuous, like:

class FileOrFolderCell: UICollectionViewCell {
    @IBOutlet weak var newBadge: UILabel!
    //...
    let emojiLabelInitialFontSize: CGFloat = 64 // <-- flagged as potential hang risk
    //...
    var isNew = false { // <-- potential hang risk
        didSet {
            newBadge.isHidden = !isNew
        }
    }
//...
}

There is no I/O that I can see in my code. What are those warnings all about? Can anybody offer insights on how to address this? This was not happening in Xcode 14.


Solution

  • I might advise trying Xcode 15.2. I’ve seen reports of version 15.3 introducing these sorts of issues (e.g., Firebase issue #12640, How to fix Firebase Analytics purple error, etc.). In your case, I am unsure whether this is a false-positive or just a misidentification of where the hang risk rests.

    As an aside, I’ve experienced other issues in 15.3, too (e.g., sendability false-positives, SwiftData’s ModelActor not actually moving to the actor’s context, etc.). That’s another argument for considering using 15.2.


    FWIW, Xcode is identifying (correctly or not) a potential/theoretical hang. You might want to double-check and see if you can manifest a hang. See this answer, in which I discuss using Instruments’ “Time Profiler” template and “Hangs” tool to identify hangs. You might also want to change the “Hangs” tools setting to “Include All Potential Interaction Delays”. If your code is manifesting a hang, this will help you identify the actual culprit, if any.


    As an aside, (and at the risk of sounding like a broken record) it would be very helpful to identify what precisely in your project (assuming it is not just Firebase) is leading to this error, as the snippet in the question is undoubtedly insufficient. The more feedback we can offer, the more likely that they will address it.


    The Xcode 15.3 release notes says

    Thread Performance Checker emits a new category of runtime issues called “Known Hangs” which shows developers where in their code hangs are known to affect users of their apps. (102045928)

    So, if you are receiving false-positive of “Known Hangs” in Xcode 15.3, you might simply turn off the “Thread Performance Checker” in your scheme diagnostic settings. That may avoid producing these warnings.