-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[c++-interop] Improve performance of creating a C++ std::string
from a contiguous UTF-8 Swift.String
#75608
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
Conversation
@swift-ci please smoke test |
linux compilation failed and I am trying to create a Linux virtual machine to debug the problem |
42f94ad
to
5d81136
Compare
@swift-ci please smoke test |
@swift-ci please benchmark |
Hi @egorzhdan I've made some updates to this PR;
Could you please review it again when convenient? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a massive performance improvement!
I have one question.
stdlib/public/Cxx/std/String.swift
Outdated
self.reserve(utf8.count) | ||
for char in utf8 { | ||
self.push_back(value_type(bitPattern: char)) | ||
if string.isContiguousUTF8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check necessary? I think withCString
should handle the non-contiguous case under the hood by falling back to the slow path of copying the string, which should produce similar results to the else
branch here.
So I wonder if we could just remove the else
branch in this initializer.
…m a contiguous UTF-8 `Swift.String`
5d81136
to
cbaef38
Compare
@swift-ci please test |
@swift-ci please benchmark |
The relevant bits of the benchmark: Performance (x86_64): -O
Code size: -OPerformance (x86_64): -Osize
Code size: -OsizePerformance (x86_64): -Onone
Code size: -swiftlibs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a significant performance improvement!
I think that this might have caused a regression on Windows :(
|
That is strange, the Windows CI was passing on this patch. |
|
@egorzhdan I think that this is due to the Apple CI hosts being very out of date in the VC version. |
Since #75608, the performance of `std::string` <=> `Swift.String` conversions improved significantly. To make sure the workload is significant enough for the benchmark results to be noise-free, this bumps the size of Swift strings that are being tested.
Since #75608, the performance of `std::string` <=> `Swift.String` conversions improved significantly. To make sure the workload is significant enough for the benchmark results to be noise-free, this bumps the size of Swift strings that are being tested.
Improve performance of creating a C++
std::string
from a contiguous UTF-8Swift.String
#75110