Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14938] Exponential Compile Times from stacking certain SwiftUI modifiers #57280

Closed
swift-ci opened this issue Jul 17, 2021 · 2 comments
Closed
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14938
Radar rdar://problem/80820394
Original Reporter juliand665 (JIRA User)
Type Bug
Environment

Xcode Version 13.0 beta 3 (13A5192i)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

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)

struct ContentView: View {
    var body: some View {
        Text("asdf")
            .background(.white) // each additional line like this doubles compile times
            .background(Color.white) // explicitly naming `Color` actually doubles compile times again (quadrupling per line)
            .background(Color.white)
            .background(Color.white)
            .background(Color.white)
            .background(Color.white)
            .background(Color.white)
    }
}

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?

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@xedin
Copy link
Member

xedin commented Nov 7, 2022

This doesn't appear to be the case with 5.7, I tried this snippet and it takes about 400 ms. to type-check on my machine. I'm going to resolve this issue for now, we can always re-open if this comes up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants