swiftlang / swift

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

[SR-13353] SIMD instructions slow: Calls to IndexingIterator.next() #55793

Open fabianfett opened 4 years ago

fabianfett commented 4 years ago
Previous ID SR-13353
Radar rdar://problem/67001499
Original Reporter @fabianfett
Type Bug

Attachment: Download

Environment Xcode: Version 12.0 beta 3 (12A8169g) MacBook Pro (16-inch, 2019) - 2,4 GHz 8-Core Intel Core i9
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Bug, simd | |Assignee | None | |Priority | Medium | Watchers: @shahmishal md5: a9b0f1c4918239714c91107417976ce1

Issue Description:

Today I've been toying around with `UUID`s. I wanted to see if I can write a fast Swift UUID parser (without Foundation). To achieve this I used the SIMD Swift instructions. Interestingly the performance was about 6times slower than using `uuid_parse` (from Darwin) and more than ten times slower compared to a simple parsing loop. (The code is attached)

Parsing UUIDs: 1000000
-----------------------------
uuid_parse | took: 0.39703s
Loop UUIDKit | took: 0.22107s
SIMD UUIDKit | took: 2.65504s
Foundation | took: 0.54979s

Looking into the performance with Instruments, I've found that there are a lot of calls to `specialized IndexingIterator.next()`. Maybe I'm missing something here, but I wonder why there is an `Iterator` in use?

I assume that this might be related to: https://bugs.swift.org/browse/SR-12777

If you have any questions please reach out. My technical skills (assembler and stuff) are limited though.

swift-ci commented 4 years ago

Comment by Kyle Macomber (JIRA)

@swift-ci create

swift-ci commented 4 years ago

Comment by Kyle Macomber (JIRA)

cc @stephentyrone

shahmishal commented 4 years ago

@swift-ci create