swiftlang / swiftlang/swift-syntax
swift-syntax compiles much more slowly with WMO enabled
- Dominant language
- Swift
- Stars
- 3.7k
- Forks
- 553
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 16
Description
### Description
This is a pretty open-ended issue, but I wanted to file some observations to see if folks have insight about possible improvements we can make here.
I observed recently that WMO makes swift-syntax compile an order of magnitude (!) slower than without WMO. From some recent testing (iMac Pro 2017, 18-core 2.3 GHz Core Intel Xeon W, 128GB RAM):
* Not optimized (SPM debug build, `swift build -v --target SwiftSyntax`): 17.34 sec
* Optimized but no WMO (SPM debug build + `-O`, `swift build -v --target SwiftSyntax -Xswiftc -O`): 37.85 sec
* Optimized and WMO (SPM release build, `swift build -c release -v --target SwiftSyntax`): 263.27 sec
Granted, SwiftSyntax is a _big_ module with lots of generated code, so it's going to take some time to compile, but the WMO situation looks a bit grim. A big part of the problem could just be forcing so much complex code into a single frontend invocation instead of parallelizing it across multiple cores, which is unavoidable with WMO. I did a build with `-stats-output-dir / -profile-stats-events / -trace-stats-events` (the logging made the build take >900 sec) and now have a 2GB CSV file and some flamegraphs which I'll try to analyze...

I was wondering if this could cause problems with macros in the future; once they start using standalone executables with SwiftSyntax as a package dependency, folks with a strong focus on build performance will likely want their macro binaries compiled with optimizations, and SwiftPM's default for release mode is to enable WMO. Could the current performance be a major bottleneck if it's not addressed?
But even excluding that use case, I wonder if there is any tuning that's possible to close this gap?
### Steps to Reproduce
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.