swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-13799] Boolean Comparison Extremely Slow #56196

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13799
Radar rdar://problem/70892080
Original Reporter DeskA (JIRA User)
Type Bug
Environment Swift 5.3
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | None | |Priority | Medium | md5: db9c4c36968f95770af1e55b5bdecdbc

Issue Description:

```
public override func hasItems(in: Store) -> Bool {
guard let items = store.storage?.items else { return false }
let hasNoItems: Bool = items.isEmpty
return hasNoItems == false
}
```
This takes 400ms to type-check.

```
public override func hasItems(in: Store) -> Bool {
guard let items = store.storage?.items else { return false }
return !items.isEmpty
}
```
This takes less than 10ms to type-check.

Boolean comparisons are extremely slow when compiling swift. It's well known that swift is a slow language, but this seems extreme.

typesanitizer commented 4 years ago

@swift-ci create

swift-ci commented 4 years ago

Comment by DeskA (JIRA)

The cause of this seems to be that BooleanLiteralType is reassignable, so for the odd chance that someone does that, swift is incredibly slow.

I know that swift is a minefield of performance issues and slow type checking, but it would be nice to fix this and hsve a compiler shortcut