简体   繁体   中英

iOS App is >20x slower after building with Xcode 11

I have an app (Xcode project) that I developed for iOS 12 (with Xcode 10, Swift 4.2) which I now want to rebuild for iOS 13 using Xcode 11.

When I opened the project in Xcode 11, built and run the project, I found that my app was suddenly more than 20 times slower! I checked multiple times that Release configuration was selected and that the same compile flags were used as in Xcode 10. Needless to say, compiler optimisations are maxed out, just like in Xcode 10.

The app uses a lot of SIMD operations ( float4 , float3 , float4x4 , etc.) and works with pointers (eg UnsafeMutablePointer<float4> ). I found that Xcode 11 showed me that simd types like float4 are now deprecated and typealias ed to new SIMD structs.

Is there something obvious I should know about porting from iOS 12 to iOS 13? Can this change of SIMD types be the source of such terrible decrease in performance? How do I restore the original speeds (iOS 13 seems like a downgrade)?

My money is on Xcode 11. Apple probably changed the compiler, or compiler settings, in a way that affected the generation of matrix math instructions.

Apple's major releases of Xcode definitely break stuff sometimes, and it can take a while for them to sort it out.

Try building for iOS 12 while using Xcode 11. Then take the same project and build it from Xcode 10.2.

My company's app is HUGE, and build times went up by ≈3X under Xcode 11. It's quite painful. That's a different issue than execution speed, obviously, but it still tells you that there we big changes to the build process.

After I rewrote the SIMD-heavy Swift codebase to Objective-C, the old performance was restored. Objective-C thankfully still uses the good old SIMD data types without pointless wrappers.

The performance correlates with changes in Swift's implementation of SIMD. In Xcode 10.1 and older, Swift used built-in SIMD data types. With Xcode 10.2 (and newer), Apple added useless Object-Oriented wrapper for SIMD data types (eg float3 is typealias for SIMD4<Float> ) and operations and didn't even bother to test the performance, which made my code more than 20x slower .

Sometimes you just need speed, don't force Protocol-oriented design where it doesn't belong to.

It doesn't matter if you choose to use Swift 4 or target iOS 12 in Xcode 10.2 and newer, you'll still get the same, bad SIMD performance.

TL;DR: Apple messed-up pre-Swift-5 SIMD levels of performance in Xcode 10.2 and newer. Port your SIMD-heavy code to Objective-C to get good old levels performance (>20x faster in my case). Let's hope Apple doesn't touch Objective-C or we're soon going to write in Neon assembly to get decent performance...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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