简体   繁体   English

为什么在模拟器中启动应用程序后 xcode 控制台输出缓慢?

[英]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.在昨天的马拉松比赛中(从早上 7 点到午夜过去),我突然遇到一个问题,即在模拟器中启动应用程序后,立即点击带有打印到控制台的按钮和滑动视图不会导致任何更改大约 15 秒。 Eventually (10 - 15 seconds) the console output appears, the views swipe and it seems normal again.最终(10 - 15 秒)控制台输出出现,视图滑动,看起来又正常了。

I am using Xcode version 12.5 (12E262) on Big Sur 11.2.3我在 Big Sur 11.2.3 上使用 Xcode 版本 12.5 (12E262)

I have looked at these, and countless others:我看过这些,还有无数其他的:

iPhone Simulator suddenly started running very slow iPhone模拟器突然开始运行很慢

Xcode freezes on startup while loading project 加载项目时 Xcode 在启动时冻结

I removed the project's folder from Derived Data, I confirmed "Slow Animations" is not checked.我从派生数据中删除了项目的文件夹,我确认没有选中“慢速动画”。 I did not remove "xcuserdata" folder.我没有删除“xcuserdata”文件夹。 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)?我是否口吃并按下了组合键(Shift 和 CMD-T 上的三击都用于切换我学到的慢速动画)? 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).我花了一整天的时间重构我的项目,以减少 Objective-C 和 UIKit 代码并更好地利用可组合架构 (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所以我可能会在昨晚从下午 3 点到午夜失去工作,或者在我有磁盘空间来安装 12.5.1 之前忍受这个

Any insights would be most welcome任何见解将是最受欢迎的

So I ran a timer profile -- see this awesome article:所以我运行了一个计时器配置文件——看这篇很棒的文章:

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

I came up with this:我想出了这个:

第一张快照

Which led to this:这导致了这个:

第二个快照

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!我希望这可以帮助其他人,感谢阅读!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM