Performance drop after Xcode9/Swift 4 migration

Two years ago, I started developing a Scheme interpreter in Swift from scratch. I recently migrated the code from Swift 3 to Swift 4 using the migration tool, and eventually switched off @objc inference. I was expecting that at this stage, my compiled binary would perform at least as well as with Swift 3. So, I was surprised to see that even if compiled as a release, my interpreter was significantly slower (factor 2 on trivial microbenchmarks). Yesterday, I coincidentally compiled my binary with the Swift Package Manager. To my surprise, the resulting binary executes much faster on the microbenchmarks I tried (at least as fast as before with Swift 3). The only real difference I can see is that SPM linked everything statically, whereas my Xcode/Carthage based application is linked dynamically. But that alone, can't explain the performance difference.


I was wondering if someone could give me some advice on suitable ways to debug this issue? Did anyone experience something similar after the migration from Swift 3 to Swift 4? I've also checked the automatically migrated project settings, and I can't see anything suspicious either.


Thanks,

Matthias

Replies

So, I was surprised to see that even if compiled as a release, my interpreter was significantly slower …

The first thing I’d do is look through the build transcripts to make sure that your Release build configuration in resulting in the correct optimisation flags being passed to Swift.

The only real difference I can see is that SPM linked everything statically, whereas my Xcode/Carthage based application is linked dynamically. But that alone, can't explain the performance difference.

That depends on how your code is distributed across dynamic libraries. A dylib boundary puts serious limits on what optimisations can be done, so if you have a hot path that bounces back and forward across that boundary you can see serious performance improvements from whole module optimisations.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"