我有一个正在尝试迁移到新项目的应用程序。我正在异步主线程中处理繁重的操作。在我的旧项目中,完成此任务只需要 1 秒,但在我的新项目中,完成相同任务需要 6-7 秒。
我观察了 CPU 使用情况,看起来新应用使用的 CPU 更少,获得的线程也很少,而旧应用则获得了很多线程来完成相同的任务。 PS:我用的是同一台设备。
什么会导致这种情况?有什么想法或建议吗?
谢谢。
最佳答案
终于找到问题了。这是由 Xcode Build Settings
中的 Optimization Level
设置引起的。新建项目时,默认Debug
优化级别为none
,Release
优化级别为Fastest, Smallest [-Os]
因此,当我将 Debug 更改为 Fastest, Smallest [-Os]
时,我的任务完成时间下降到 1 秒。
来自苹果:
The Xcode compiler supports optimization options that let you choose whether you prefer a smaller binary size, faster code, or faster build times. For new projects, Xcode automatically disables optimizations for the debug build configuration and selects the Fastest, Smallest option for the release build configuration. Code optimizations of any kind result in slower build times because of the extra work involved in the optimization process. If your code is changing, as it does during the development cycle, you do not want optimizations enabled. As you near the end of your development cycle, though, the release build configuration can give you an indication of the size of your finished product, so the Fastest, Smallest option is appropriate.
如果您想阅读有关优化级别和性能的更多信息:Tuning for Performance and Responsiveness
旁注:在 Debug模式下将优化级别更改为最快、最小 [-0s] 可能会影响调试器断点,并且它会突然出现。
干杯。
关于ios - 相同的操作在两个相同的项目中执行时间不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61031271/