性能的 XCode 构建设置 - iPhone 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1477137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:51:54  来源:igfitidea点击:

XCode build settings for performance - iPhone apps

iphoneperformancexcodesettings

提问by Jugs

Is there any articles available online where can I find some tips on improving the iPhone application performance. I have read Apple docs on Memory Management and CPU cycles, but they are not very helpful.

是否有任何在线文章可以找到有关提高 iPhone 应用程序性能的一些技巧。我已经阅读了关于内存管理和 CPU 周期的 Apple 文档,但它们并不是很有帮助。

Also can someone suggest a few XCode settings that could improve the performance of the application (release version)?

也有人可以建议一些可以提高应用程序性能的 XCode 设置(发布版本)?

Thanks Jugs

谢谢水罐

回答by bbum

Short of measuring and optimizing, compiler optimization level is just about the only thing that will impact the performance of your application. Typically, you'll want an optimization level of -Os; that is, optimized code, but optimized for size, too. Since the iPhone's memory is limited, reducing code size is useful.

除了测量和优化之外,编译器优化级别几乎是唯一会影响应用程序性能的因素。通常,您需要优化级别-Os;也就是说,优化了代码,但也优化了大小。由于 iPhone 的内存有限,因此减少代码大小很有用。

Beyond that, you are going to have to measure the performance of your application and react accordingly. There are many tools in Instruments and otherwise to help you in this task. The tools are actually pretty darned good, once you figure them out.

除此之外,您将不得不衡量应用程序的性能并做出相应的反应。Instruments 中有许多工具可以帮助您完成此任务。一旦你弄清楚了,这些工具实际上非常好。

Given that you haven't actually measured anything yet (which is good -- make it work, make it right, make it fast), there may be low hanging fruit. Do you redraw something too often? Have some automatic timed event firing too fast? etc... Just don't fall into the trap of premature optimization; the need to measure & react is paramount to successful optimization.

鉴于您实际上还没有测量任何东西(这很好——让它工作、使它正确、让它快速),可能会有一些低悬的果实。你是否经常重绘某些东西?是否有一些自动定时事件触发太快?等等...只是不要陷入过早优化的陷阱;衡量和反应的需要对于成功的优化至关重要。

Note also that you can do coarse grained optimization via the Simulator, but you really need to do the analysis on the app running on the device to do final polish optimization.

另请注意,您可以通过模拟器进行粗粒度优化,但您确实需要对设备上运行的应用程序进行分析才能进行最终的优化。



(1) Sounds like your database query is really slow. Not knowing the schema, etc, it is hard to know if that is truly the case.

(1) 听起来您的数据库查询真的很慢。不知道模式等,很难知道情况是否真的如此。

(2) When doing performance analysis and the time is consumed by a function in an unknown library, look up the stack and see what is calling that library to figure out why your app is triggering the performance slowdown.

(2) 在做性能分析时,时间被未知库中的函数消耗了,查看堆栈,看看是什么调用了该库,以找出您的应用程序触发性能下降的原因。

回答by Stephen Canon

Basically, what bbum said. Get actual data and go from there. That said, there are a couple compile flags that can have substantial effect:

基本上,bbum 所说的。获取实际数据并从那里开始。也就是说,有几个编译标志可以产生实质性的影响:

  • Make sure you aren't compiling at -O0. As bbum noted, -Os is probably what you want.
  • If you are doing a lot of floating-point computation, make sure that "Compile for Thumb" (-mthumb) is not set when building for ARMv6. The thumb instruction set on ARMv6 doesn't have floating-point instructions, so you hit a shim for every floating-point operation you use. Often this is offset by the code size savings, but if you have a lot of floating-point it can be a performance hazard. Note that you can build part of your project for thumb and part with it turned off. Also note that the thumb2 instruction set on ARMv7 supports floating-point.
  • 确保您没有在 -O0 下编译。正如 bbum 所指出的,-Os 可能就是你想要的。
  • 如果您要进行大量浮点计算,请确保在为 ARMv6 构建时未设置“为 Thumb 编译”(-mthumb)。ARMv6 上的拇指指令集没有浮点指令,因此您对使用的每个浮点运算都进行了填充。通常这会被代码大小的节省所抵消,但如果您有很多浮点数,则可能会带来性能风险。请注意,您可以为拇指构建项目的一部分,而将其部分关闭。另请注意,ARMv7 上的 thumb2 指令集支持浮点。

回答by mahboudz

Best way to improve iPhone performance is to improve app performance, and not just through compiler optimizations, but through better algorithms.

提高 iPhone 性能的最佳方法是提高应用程序性能,不仅仅是通过编译器优化,而是通过更好的算法。

Generally compiler optimizations may improve your performance by some single or two digit percentage. Code optimization using better algorithms, caching, re-architecting, etc. could have a three digit percentage improvement.

通常,编译器优化可以将您的性能提高一个或两位数的百分比。使用更好的算法、缓存、重新架构等的代码优化可以有三位数的改进。

I've never found a compiler setting that noticeably improves my app's performance. Your miles may vary.

我从来没有找到可以显着提高我的应用程序性能的编译器设置。您的里程可能会有所不同。