衡量iOS应用启动性能的典型方法?

时间:2021-07-12 05:54:51

I've been asked to reduce the startup time of an iOS application. I am very familiar with the platform/tools in general but I haven't focussed upon application startup time before. I'm wondering if there are known patterns for attacking this problem?

我被要求减少iOS应用程序的启动时间。我对平台/工具一般非常熟悉,但我之前没有专注于应用程序启动时间。我想知道是否有已知的攻击这个问题的模式?

I realize that I can simply measure the time it takes to go from main() through the completion of application:didFinishLaunchingWithOptions: (which includes any background loading tasks), but again, I am hoping there might be a more standardized way to do this.

我意识到我可以简单地测量从main()到完成应用程序所需的时间:didFinishLaunchingWithOptions :(包括任何后台加载任务),但同样,我希望可能有更标准化的方法来执行此操作。

Any suggestions would be greatly appreciated!

任何建议将不胜感激!

-M

-M

2 个解决方案

#1


13  

from WWDC 2012 session 235

来自WWDC 2012会议235

set the start point at the first line of code in main.m

在main.m的第一行代码中设置起始点

#import <UIKit/UIKit.h>

CFAbsoluteTime StartTime;

int main(int argc, char *argv[])
{
    StartTime = CFAbsoluteTimeGetCurrent();

    @autoreleasepool {
        ...

set the end point somewhere in AppDelegate's application:didFinishLaunchingWithOptions:

在AppDelegate的应用程序中设置终点:didFinishLaunchingWithOptions:

extern CFAbsoluteTime StartTime;
 ...
dispatch_async(dispatch_get_main_queue(), ^{
    NSLog(@"Launched in %f sec", CFAbsoluteTimeGetCurrent() - StartTime);
});

#2


1  

Your method sounds like the correct one (I recommend using CFAbsoluteTime for your measurements).

您的方法听起来是正确的(我建议您使用CFAbsoluteTime进行测量)。

One thing which may help you reduce the launch time is to avoid having View Controllers loaded from nibs on application launch. If I am not mistaken this forces them to be loaded into memory even before your app launches. Instead, alloc and init your view controllers dynamically when you need them. Note that you can still have the Views you'd like to be loaded by the view controllers stored in Nibs, you don't have to stop using IB. Just don't use IB to set static outlets for your app delegate.

可以帮助您减少启动时间的一件事是避免在应用程序启动时从nib加载View Controllers。如果我没有弄错,这会迫使它们在应用程序启动之前加载到内存中。而是在需要时动态分配和初始化视图控制器。请注意,您仍然可以通过存储在Nib中的视图控制器加载视图,您不必停止使用IB。只是不要使用IB为您的app代理设置静态插座。

#1


13  

from WWDC 2012 session 235

来自WWDC 2012会议235

set the start point at the first line of code in main.m

在main.m的第一行代码中设置起始点

#import <UIKit/UIKit.h>

CFAbsoluteTime StartTime;

int main(int argc, char *argv[])
{
    StartTime = CFAbsoluteTimeGetCurrent();

    @autoreleasepool {
        ...

set the end point somewhere in AppDelegate's application:didFinishLaunchingWithOptions:

在AppDelegate的应用程序中设置终点:didFinishLaunchingWithOptions:

extern CFAbsoluteTime StartTime;
 ...
dispatch_async(dispatch_get_main_queue(), ^{
    NSLog(@"Launched in %f sec", CFAbsoluteTimeGetCurrent() - StartTime);
});

#2


1  

Your method sounds like the correct one (I recommend using CFAbsoluteTime for your measurements).

您的方法听起来是正确的(我建议您使用CFAbsoluteTime进行测量)。

One thing which may help you reduce the launch time is to avoid having View Controllers loaded from nibs on application launch. If I am not mistaken this forces them to be loaded into memory even before your app launches. Instead, alloc and init your view controllers dynamically when you need them. Note that you can still have the Views you'd like to be loaded by the view controllers stored in Nibs, you don't have to stop using IB. Just don't use IB to set static outlets for your app delegate.

可以帮助您减少启动时间的一件事是避免在应用程序启动时从nib加载View Controllers。如果我没有弄错,这会迫使它们在应用程序启动之前加载到内存中。而是在需要时动态分配和初始化视图控制器。请注意,您仍然可以通过存储在Nib中的视图控制器加载视图,您不必停止使用IB。只是不要使用IB为您的app代理设置静态插座。