swiftobjective-cxcodeswiftuiswift-composable-architecture

why is xcode console output sluggish after app launch in simulator?


During a marathon session yesterday (from 7 am until past midnight), I suddenly ran into an issue where, immediately after launching the app in the simulator, button taps with prints to the console and swipes on views wouldn't result in any change for about 15 seconds. Eventually (10 - 15 seconds) the console output appears, the views swipe and it seems normal again.

I am using Xcode version 12.5 (12E262) on Big Sur 11.2.3

I have looked at these, and countless others:

iPhone Simulator suddenly started running very slow

Xcode freezes on startup while loading project

I removed the project's folder from Derived Data, I confirmed "Slow Animations" is not checked. I did not remove "xcuserdata" folder. I just don't know where to turn to debug this issue. Has anyone seen this behavior? Did I stutter and hit a key combination (Triple tap on Shift and CMD-T both used to toggle slow animations I've learned)? I feel like I've added code that is triggering this, but I can't be sure. I had spent the entire day refactoring my project to reduce the Objective-C and UIKit code and make better use of Composable Architecture (TCA). If people suggest debug steps I could perform I'll try them out and report back. I just don't know how to continue debugging this issue.

Backups from before the day's changes do not exhibit this behavior. I copied the project to a new directory and replaced all source code with the backed up source code. And that works fine. So I can lose the work from 3 pm to midnight last night or suffer through this until I have disk space to install 12.5.1

Any insights would be most welcome


Solution

  • So I ran a timer profile -- see this awesome article:

    https://www.avanderlee.com/debugging/xcode-instruments-time-profiler/

    I came up with this:

    First snapshot

    Which led to this:

    Second Snapshot

    And I understood where I introduced the problem:

    var selectedNibIndex: Int = 0 {
            didSet {
                brush = WDBrush.from(index: selectedNibIndex)!
                cameoImage = BrushStrokeImageView(paintBrush: brush)
                dictionary = brush.wdPropertiesDictionary() as! [String: WDProperty]
            }
        }
    

    this is new code, and it is placed inside a struct which is constantly being rebuilt.

    I will move it out of there.

    **

    I guess the answer to my question is to run the app under the time profiler and let it tell you where the problem is.

    **

    And marathon sessions aren't always a good idea. I would have caught the problem sooner if I hadn't bitten off such a big task. There was a two hour period where it wouldn't compile and I shouldn't have let that happen. By the time I got it to compile after some changes I had changed so many things I could no longer see the forest for the trees.

    I hope this can help others, thanks for reading!