Skip to content

[SR-11736] Type checking is unacceptably slow, and got significantly worse with Xcode 11 #54143

@swift-ci

Description

@swift-ci
Previous ID SR-11736
Radar None
Original Reporter mluisbrown (JIRA User)
Type Bug

Attachment: Download

Environment

macOS Catalina 10.15.1

Xcode 11.1

MacBook Pro 15 (2018), 2.9 GHz 6-Core Intel Core i9, 32GB of RAM

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee @harlanhaskins
Priority Medium

md5: 255a6b937472bfd319b643906829143f

Issue Description:

Xcode 11 / Swift 5.1 introduced significant increases in the time taken to type check Swift code. Even quite simple expressions can now take longer than 100ms.

This problem was first raised on twitter by my colleague David Rodrigues: https://twitter.com/dmcrodrigues/status/1192136776212713472

The example project attached (Type Checking Issues.zip) has a number of examples taken from a larger project where the number of "time to type-check" warnings has skyrocketed from 2 or 3 to 40 or 50 since we migrated to Xcode 11.

An example warning output is this

As you move the selection through these warnings, Xcode also seems to be continuously re-compiling the code (even though nothing has changed) and regenerating new type check time warnings as shown in this video:

XcodeTypeCheck.mov

Two of the worst examples are the following:

import UIKit

class SomeViewController: UIViewController {

    private func updatePreferredContentSize() {
        preferredContentSize = CGSize(
            width: view.bounds.width,
            height: (view.subviews.map { $0.frame.height }.reduce(+) ?? 0) + 20.0
        )
    }
}

and this one:

import Foundation

extension Int {

    public var days: TimeInterval {
        return TimeInterval(self) * 24.hours
    }

    public var hours: TimeInterval {
        return TimeInterval(self) * 60.minutes
    }

    public var minutes: TimeInterval {
        return TimeInterval(self) * 60.seconds
    }

    public var seconds: TimeInterval {
        return TimeInterval(self)
    }
}

These type checker performance degradations have also significantly increased overall build times, which have increased between 15-20% since we moved to Xcode 11.

Note: building the project using xcodebuild -configuration Debug -sdk iphonesimulator the type check times are not as bad, but still there.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions