[SR-14938] Exponential Compile Times from stacking certain SwiftUI modifiers #57280
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
performance
type checker
Area → compiler: Semantic analysis
Environment
Xcode Version 13.0 beta 3 (13A5192i)
Additional Detail from JIRA
md5: b3401e347061f16d5950ce820d9875a8
Issue Description:
I hope this is an appropriate place to report this! I'm aware SwiftUI is not part of the Swift project, but I'd wager this exponential type-checking time is a problem with the Swift compiler, not SwiftUI. However, it does mean you'll need an environment with SwiftUI to reproduce. Maybe it would be valuable to come up with a MWE that exhibits the same symptoms without SwiftUI?
Anyway, the problem is exhibited by the following snippet: (I suggest compiling with
-Xfrontend -warn-long-function-bodies=100
)As written here, this snippet takes almost 2 seconds to compile on my machine, but the ugly part is that the compile times grow exponentially with each additional chained modifier as above, easily reaching hours and even days, especially with more complex base bodies than a simple
Text
. Many modifiers (like e.g. a simple.padding()
) don't exhibit this issue, but I'm sure there's a bunch that do. This should serve as a good starting point for investigation though—perhaps it's simply a problem with the new syntax introduced in SE-0299?Additionally, simply the fact that compile times can grow this long (the longest I let it run for and succeed in my testing was ~20mins) feels like a bug—shouldn't it be cutting off type checking after at most a minute and deciding that it's taking too long?
The text was updated successfully, but these errors were encountered: