What are the tradeoffs of -cross-module-optimization?

Just a small data point, tried this out on a small sample project and got a 4x reduction in performance (reproducible) with cross-module-optimization enabled on my M1 Max laptop:

hassila@max ~/D/G/p/swift-benchmark (main)> swift run -c release
Building for production...
Build complete! (0.08s)
Start test
1064784 usec
hassila@max ~/D/G/p/swift-benchmark (main)> swift run -Xswiftc -cross-module-optimization -c release
Building for production...
[4/4] Linking swift-benchmark
Build complete! (2.10s)
Start test
4391472 usec
hassila@max ~/D/G/p/swift-benchmark (main)> 

It is a small test project encoding simple messages with flat buffers (the flatbuffers swift code is fairly well annotated with @inline etc, was just curious to try this out and see what the difference - if any - was).

Is cross-module-optimization still something that is on the radar - worthwhile filing a report on it?f

2 Likes