To make a short story, I looked for a performance issue in my 32-bit iPhone app. In the process, I deleted a third-party library, which limited me to 32 bits, and when I built for arm64, I saw a 2-fold improvement in the code section not related to the specified library.
I had the impression that just adding arm64 to Valid Architectures would not lead to a significant increase in performance, so I wonder if my case is just an anomaly.
In the process of smoothing my application to several tens of lines that show the difference in performance, I lost some of the gain, but it is still significant. Minor changes, such as the number of characters in the dictionary keys and the combination of the number of objects in the keys, seem to be of great importance.
The following code is the entire sample application placed in viewDidLoad. Built with arm64 using Xcode 5.1, running on my iPhone 5s (iOS 7.1), the average time to retrieve 2075 dictionary objects is about 0.6 seconds, armv7s is built, about 1.0 seconds.
Is there a simple explanation for the performance improvement that can be used 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);