我对 Xcode 比较陌生。我们正在测试一个显示传入数据的应用程序,它需要尽可能快。对于其他平台,我需要从“调试”更改为“发布”,以便启动优化并删除调试代码,这会对速度产生深远影响。要在快速/ Release模式下构建,我需要在 Xcode 中执行哪些等效操作?
(我在谷歌上搜索这个,看到很多点击似乎都在附近,但我可能对术语有点困惑,我可能需要把它简化一点:))
感谢您的帮助。
最佳答案
第一步是如上所述设置发布的优化级别。这里有很多选择。来自 clang LLVM 编译器手册页 (man cc)——(注意 -Os 是 Release 的默认值):
Code Generation Options
-O0 -O1 -O2 -O3 -Ofast -Os -Oz -O -O4
Specify which optimization level to use:
-O0 Means "no optimization": this level compiles the fastest and
generates the most debuggable code.
-O1 Somewhere between -O0 and -O2.
-O2 Moderate level of optimization which enables most
optimizations.
-O3 Like -O2, except that it enables optimizations that take longer
to perform or that may generate larger code (in an attempt to
make the program run faster).
-Ofast
Enables all the optimizations from -O3 along with other
aggressive optimizations that may violate strict compliance
with language standards.
-Os Like -O2 with extra optimizations to reduce code size.
-Oz Like -Os (and thus -O2), but reduces code size further.
-O Equivalent to -O2.
-O4 and higher
Currently equivalent to -O3
您会注意到“Ofast”选项——非常快,但有点冒险。
第二步是考虑是否启用“展开循环”。我读到这在某些代码中可以使速度提高 15%(以调试为代价,但对于发布版本来说不是问题)。
接下来,考虑是否要构建和使用优化配置文件。参见 Apple有关详细信息,但要点是:
Profile Guided Optimization (PGO) is a means to improve compiler optimization of an app. PGO utilizes a specially instrumented build of the app to generate profile information about the most commonly used code paths and methods. The compiler then uses this profile information to focus optimization efforts on the most frequently used code, taking advantage of the extra information about how the program typically behaves to do a better job of optimization.
您可以在build设置 -> Apple LLVM 6.0 - 代码生成 -> 使用优化配置文件下定义配置文件以及是否使用它。
关于ios - 从 Xcode 构建更快的 "release"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25936254/