简体   繁体   English

arm64 objectForKey性能异常?

[英]arm64 objectForKey performance an anomaly?

To make a short story long, I was looking at a performance problem in my 32-bit iPhone app. 为了做一个很短的故事,我在32位iPhone应用程序中查看性能问题。 In the process I removed the 3rd-party library that was limiting me to 32-bit and when I built for arm64 I saw a 2-fold speed improvement in a section of code unrelated to said library. 在这个过程中,我删除了限制我为32位的第三方库,当我为arm64构建时,我看到与该库无关的代码段的速度提高了2倍。

I was under the impression that simply adding arm64 to the Valid Architectures was not going to bring a significant increase in performance so I wonder if my case is just an anomaly. 我的印象是简单地将arm64添加到有效架构中并不会带来性能的显着提升,所以我想知道我的案例是否只是一个异常现象。

In the process of whittling my app down to a few dozen lines that show the performance difference I lost some of the gain, but it's still significant. 在将我的应用程序削减到显示性能差异的几十行的过程中,我失去了一些收益,但它仍然很重要。 Seemingly minor changes like the number of characters in dictionary keys and the mix of the number of objects in the keys make a big difference. 看似微小的变化,如字典键中的字符数和键中对象数量的混合,会产生很大的不同。

The following code is the entirety of the sample app - placed in viewDidLoad. 以下代码是示例应用程序的全部内容 - 放置在viewDidLoad中。 Built with arm64 using Xcode 5.1, running on my iPhone 5s (iOS 7.1) average time to retrieve 2075 dictionary objects is about 0.6 secs, built armv7s, about 1.0 secs. 使用X64 5.1使用arm64构建,在我的iPhone 5s(iOS 7.1)上运行,检索2075个字典对象的平均时间约为0.6秒,构建armv7s,大约1.0秒。

Is there a simple explanation to the performance improvement that can be exploited in general? 对于可以在一般情况下利用的性能改进是否有一个简单的解释?

#define NUM_DICT_ENTRIES 2075
NSMutableDictionary *aDict = [[NSMutableDictionary alloc] init];
NSDictionary *keyDictionary;
for (int i = 0; i < NUM_DICT_ENTRIES; i++) {
    if (arc4random_uniform(2)) {
        keyDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                         [[NSProcessInfo processInfo] globallyUniqueString], @"entry",
                         [[NSProcessInfo processInfo] globallyUniqueString], @"category", nil];
    } else {
        keyDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                         [[NSProcessInfo processInfo] globallyUniqueString], @"entry",
                         [[NSProcessInfo processInfo] globallyUniqueString], @"category",
                         [[NSProcessInfo processInfo] globallyUniqueString], @"article", nil];
    }
    NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:[[NSProcessInfo processInfo] globallyUniqueString],@"xyzzy", nil];
    [aDict setObject:d forKey:keyDictionary];
}

#define NUM_ITERATIONS 10

NSTimeInterval runTime = 0;

for (int i = 0; i < NUM_ITERATIONS; i++) {
    NSDate *start = [NSDate date];

    for (NSDictionary *keyDictionary in aDict) {
        [[aDict objectForKey:keyDictionary] objectForKey:@"xyzzy"];
    }

    runTime += [[NSDate date] timeIntervalSinceDate:start];
}

NSLog(@"average of %d iterations = %f", NUM_ITERATIONS, runTime/NUM_ITERATIONS);

It's hard to say what improved for this test specifically. 很难说具体改进了这项测试。 There are many changes in arm64 vs armv7 which can affect performance. arm64与armv7有很多变化,可能会影响性能。 Some examples: 一些例子:

  • arm64 uses Objective-C tagged pointer objects for some types. arm64对某些类型使用Objective-C标记指针对象。 Code that uses those types may be faster or use less memory. 使用这些类型的代码可能更快或使用更少的内存。
  • arm64 stores Objective-C retain counts for most objects in the object itself instead of in a separate table. arm64存储Objective-C保留对象本身中大多数对象的计数,而不是单独的表。 Code that performs lots of retain/release traffic may be faster. 执行大量保留/释放流量的代码可能更快。
  • The arm64 instruction set is more efficient for some operations. arm64指令集对某些操作更有效。 Code that performs the right sort of math or memory manipulations may be faster. 执行正确的数学或内存操作的代码可能更快。
  • arm64's 64-bit pointers occupy more memory. arm64的64位指针占用更多内存。 Pointer-heavy memory-constrained code may be slower. 指针大量内存约束代码可能会更慢。

Instruments traces of the two versions might uncover the performance differences. 这两个版本的仪器跟踪可能会发现性能差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM