After having just finished moving some code into a Swift package, we are now seeing benchmarks taking almost 20 times longer to complete as measured in Instruments using signposts. What used to take around 3 seconds is now taking just over 1 minute to complete.
The code in question manipulates a bunch of
structs that are stored in
Arrays and then accumulates the results and returns them. Most of the
structs include at least one generic property.
I assume we're running into the performance limitations of cross module optimization, though I wasn't aware it could be this significant. I see some older PRs and discussions around this topic but was curious what the current state of affairs was.
How are others managing performance sensitive code in packages, especially code that involves generics?
From what I can tell, the Swift Algorithms and Swift Collection packages make very liberal use of
@inlinable almost everywhere.
Our package is not available to the public and is used only in applications that we have full access to the source code. Should we really be trying to inline as many hot-path methods as possible that are in the package?
Snippet of a trace that used to take 3.31 seconds but now takes 1.09 min:
macOS 12+, Xcode 13, M1 Mini