You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SR-1577] Ternary operator much slower to compile than if / else #44186
picks is an array of instances of an NSManagedObject subclass, position and pick_line are both optional Integer types. (I don't know if this is relevant).
Not sure if this should be labelled "Performance". Is that for issues in the compilation time or the performance of the compiled code.
There are several factors that would make the first one slower, the main one being that everything's type-checked together. Specifically:
As a multi-statement closure, the body of the second is type-checked separately from the call to sort.
The types of the branches of the ternary operator must match, so it all gets type-checked together. We could probably separate out the checking for the condition, but we don't. The second version checks all three pieces separately, and uses the type pre-established by the call to sort.
Activity
belkadan commentedon May 21, 2016
The label's context-sensitive. Maybe we should have CompilerPerf and RunTimePerf instead.
belkadan commentedon May 21, 2016
There are several factors that would make the first one slower, the main one being that everything's type-checked together. Specifically:
As a multi-statement closure, the body of the second is type-checked separately from the call to
sort.The types of the branches of the ternary operator must match, so it all gets type-checked together. We could probably separate out the checking for the condition, but we don't. The second version checks all three pieces separately, and uses the type pre-established by the call to
sort.swift-ci commentedon Feb 21, 2017
Comment by Luis Grimaldo (JIRA)
How come this does not have higher priority?
Type-checking in general for Swift seems to be extremely slow.
slavapestov commentedon Sep 19, 2025
This specific issue might be obsolete -- sort() is now sorted(), and
Optional.<is gone.