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-10283] UTF8View significantly slower than data(using: .utf8) #52683

Closed
swift-ci opened this issue Apr 3, 2019 · 1 comment
Closed

[SR-10283] UTF8View significantly slower than data(using: .utf8) #52683

swift-ci opened this issue Apr 3, 2019 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. performance standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2019

Previous ID SR-10283
Radar None
Original Reporter tomquist (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.4 (18E226)
MacBook Pro (15-inch, 2017), 2,8 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @Catfish-Man
Priority Medium

md5: 4df4db68bea474803c18008187576259

Issue Description:

As discussed with @milseman on Twitter (https://twitter.com/tomqueue/status/1113180317844746241) I create this issue.
Since Swift 5 now natively uses UTF8 for Strings I'd expect the Test `testPerformanceOfUTF8View` be comparably fast as `testPerformanceOfData` but it's significantly slower.

// Executed with optimization -Os on a MacBook Pro (15-inch, 2017) 2,8 GHz Intel Core i7
class StringPerformanceTest: XCTestCase {

    // Takes on average 0.062 sec
    func testPerformanceOfUTF8View() {
        let data = "_cqeFf~cjVf@p@fA}AtAoB`ArAx@hA`GbIvDiFv@gAh@t@X\\|@z@`@Z\\Xf@Vf@VpA\\tATJ@NBBkC".data(using: .utf8)!
        let string = String(decoding: data, as: UTF8.self)
        measure {
            for _ in 0 ... 10000 {
                var count = 0
                for _ in string.utf8 {
                    count += 1
                }
            }
        }
    }

    // Takes on average 0.026 sec
    func testPerformanceOfData() {
        let data = "_cqeFf~cjVf@p@fA}AtAoB`ArAx@hA`GbIvDiFv@gAh@t@X\\|@z@`@Z\\Xf@Vf@VpA\\tATJ@NBBkC".data(using: .utf8)!
        let string = String(decoding: data, as: UTF8.self)
        measure {
            for _ in 0 ... 10000 {
                var count = 0
                for _ in string.data(using: .utf8)! {
                    count += 1
                }
            }
        }
    }
}
@Catfish-Man
Copy link
Member

This is fixed in 5.1! I extracted the benchmarks out into a standalone test with a higher iteration count and I'm getting these times now:

Took 0.011713981628417969 seconds

Took 0.09220004081726074 seconds

So the native String route is now much faster.

@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. performance standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants