-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[String] [Foundation] perf: UTF8 String -> Data #24215
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
[String] [Foundation] perf: UTF8 String -> Data #24215
Conversation
Currently, `str.data(using:allowLossyConversion)` always bridges via `NSString`. As `String` is now natively UTF8 we can fastpath this conversion in the case where the user requests UTF8 encoding. A benchmark for this was previously added in swiftlang#22648.
@swift-ci please benchmark |
Performance: -O
Performance: -Osize
Performance: -Onone
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
10x for small strings, niiiiiiiiiiice 😎 @itaiferber @milseman please review. |
Sweet! CC @Catfish-Man |
Also, let's cherry-pick this onto the 5.1 branch |
@swift-ci please smoke test |
Please merge when you're ready - thanks. |
Currently,
str.data(using:allowLossyConversion:)
always bridges viaNSString
.As
String
is now natively UTF-8 we can fastpath this conversion in thecase where the user requests UTF-8 encoding.
A benchmark for this was previously added in #22648.