Xcode 7.2b4 (7C62b): [Swift] Expression takes a long time to compile
| Originator: | janoschhildebrand | ||
| Number: | rdar://23620262 | Date Originated: | 20-Nov-2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.2b4 (7C62b) |
| Classification: | Performance | Reproducible: | Always |
Summary:
The following code snippet takes a long time to compile:
import Foundation
struct DurationList {
private var runtimes: [Double] = []
var mean: Double {
let total = runtimes.reduce(0) { return $0 + $1 }
return total / Double(runtimes.count)
}
var stddev: Double {
let mean = self.mean
// This relatively complex expression is the culprit
// Compiles fine when split up into 3 separate expressions
let variance = runtimes.map { $0 - mean }
.map { $0 * $0 }
.reduce(0, combine: +) / Double(runtimes.count)
return sqrt(variance)
}
}
Steps to Reproduce:
1. Download the attached project
2. Open the project & build
Expected Results:
The project should build in reasonable time.
Actual Results:
The project takes > 10s to build (on my machine).
Version:
Xcode 7.2b4 (7C62b)
Apple Swift version 2.1.1 (swiftlang-700.1.101.13 clang-700.1.81)
OS X 10.11.1 (15B42)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!