从 Xcode 更快地“发布”构建?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25936254/
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-15 05:37:21  来源:igfitidea点击:

Faster "release" build from Xcode?

iosxcode

提问by Chris

I am relatively new to Xcode. We are testing an app that displays incoming data and it needs to be as fast as possible. With other platforms I need to change from "debug" to "release" in order for optimizations to kick in and debug code to be removed, which can have a profound effect on speed. What are the equivalent things I need to do in Xcode to build in fast/release mode?

我对 Xcode 比较陌生。我们正在测试一个显示传入数据的应用程序,它需要尽可能快。对于其他平台,我需要从“调试”更改为“发布”,以便进行优化并删除调试代码,这会对速度产生深远的影响。我需要在 Xcode 中以快速/发布模式构建的等效操作是什么?

(I am googling this and see lots of hits that seem to be in the general vicinity but I might be a little thrown off by the terminology, I might need it dumbed down a bit :))

(我在谷歌上搜索这个,看到很多似乎在附近的热门歌曲,但我可能会被术语所迷惑,我可能需要把它简化一点:))

Thanks for the help.

谢谢您的帮助。

采纳答案by dasdom

Edit the scheme to use release configuration.

编辑方案以使用发布配置。

回答by David S.

The first step is to set the Optimization Level for release as described above. There are lots of options here. From the clang LLVM compiler man page (man cc) -- (note that -Os is the default for Release):

第一步是如上所述设置发布的优化级别。这里有很多选择。从 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

You will notice the 'Ofast' option -- very fast, somewhat risky.

您会注意到“Ofast”选项——非常快,但有点冒险。

A second step is to consider whether to enable "Unroll Loops". I've read that this can in some code lead to a 15% speed increase (at the expense of debugging, but not an issue for Release builds).

第二步是考虑是否启用“Unroll Loops”。我读过这可以在某些代码中导致 15% 的速度提高(以调试为代价,但对于发布版本来说不是问题)。

Next, consider whether you want to Build and use an Optimization Profile. See Applefor details, but the gist is that:

接下来,考虑您是否要构建和使用优化配置文件。有关详细信息,请参阅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.

Profile Guided Optimization (PGO) 是一种改进应用程序编译器优化的方法。PGO 利用应用程序的特殊检测构建来生成有关最常用代码路径和方法的配置文件信息。然后,编译器使用此配置文件信息将优化工作集中在最常用的代码上,利用有关程序通常如何表现的额外信息来更好地优化工作。

You define the profile and whether you use it under Build Settings -> Apple LLVM 6.0 - Code Generation -> Use Optimization Profile.

您可以在 Build Settings -> Apple LLVM 6.0 - Code Generation -> Use Optimization Profile 下定义配置文件以及是否使用它。

回答by fred foc

First have a look at this part in Xcode (screenshot of Xcode 5 but same on Xcode 6)Xcode optimization

首先在 Xcode 中查看此部分(Xcode 5 的屏幕截图,但在 Xcode 6 上相同)Xcode优化

You should also prefer PNG to Jpeg (as Jpeg requires more calculation - but are generally smaller in terms of size so better for network...) Finally, Use multi-threading. Those are (to mu humble opinion) the first steps to look at.

与 Jpeg 相比,您还应该更喜欢 PNG(因为 Jpeg 需要更多的计算——但通常尺寸更小,因此更适合网络......)最后,使用多线程。这些是(以 mu 拙见)首先要考虑的步骤。