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-9185] Performance regression with Swift 4.2 #51676

Closed
tsolomko opened this issue Nov 5, 2018 · 1 comment
Closed

[SR-9185] Performance regression with Swift 4.2 #51676

tsolomko opened this issue Nov 5, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance regression swift 4.2

Comments

@tsolomko
Copy link

tsolomko commented Nov 5, 2018

Previous ID SR-9185
Radar None
Original Reporter @tsolomko
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Everything was done on macOS 10.13.6 with Swift 4.2 from Xcode 10.1 (so it is actually 4.2.1) and Swift 4.1.3 from toolchain downloaded from swift.org website.

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

md5: d3dff7116265809804a3ad7763bb0575

Issue Description:

After upgrading to Swift 4.2 my projects became almost two times slower when compiled with Swift 4.2 compared to when compiled with Swift 4.1.3.

Here's sample code from my library:

// main.swift
import Foundation

class ByteReader {

    let data: Data

    var offset: Int

    init(data: Data) {
        self.data = data
        self.offset = data.startIndex
    }

    func byte() -> UInt8 {
        precondition(self.offset < self.data.endIndex)
        defer { self.offset += 1 }
        return self.data[self.offset]
    }

}

let byteReader = ByteReader(data: Data(count: 10_485_760))

for _ in 0..<10_000_000 {
    _ = byteReader.byte()
}

Here are the results that I am getting:

$ swiftc --version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0
$ swiftc -O main.swift
$ time ./main

real    0m0.948s
user    0m0.920s
sys 0m0.022s
$ xcrun -toolchain org.swift.41320180727a swiftc --version
Apple Swift version 4.1.3 (swift-4.1.3-RELEASE)
Target: x86_64-apple-darwin17.7.0
$ xcrun -toolchain org.swift.41320180727a swiftc -O main.swift
$ time ./main

real    0m0.450s
user    0m0.419s
sys 0m0.018s

I've also made a couple of screenshots in Instruments (see attachments).

@tsolomko
Copy link
Author

tsolomko commented Nov 5, 2018

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 regression swift 4.2
Projects
None yet
Development

No branches or pull requests

2 participants