-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SDK] Use withContiguousStorageIfAvailable in some overlay methods #22001
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
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.
Looks good to me
} | ||
withContiguousStorageIfAvailable(_clip) ?? |
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.
Minor stylistic nitpick. Just discussed it with @milseman and we agreed that it would be more readable if these two lines are reformatted as the following:
withContiguousStorageIfAvailable(_clip)
?? Array(self).withUnsafeBufferPointer(_clip)
This way it is clear that the second line is not a new statement, but instead is a previous expression continued.
What do you think?
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.
Sounds good. Updated.
.map(String._unconditionallyBridgeFromObjectiveC) | ||
} | ||
guard let str = bytes.withContiguousStorageIfAvailable(_makeString) ?? | ||
Array(bytes).withUnsafeBufferPointer(_makeString) else { |
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.
Same here.
guard let str = bytes.withContiguousStorageIfAvailable(_makeString)
?? Array(bytes).withUnsafeBufferPointer(_makeString) else {
return nil
}
That conflict is from #21959. When you resolve it, can you make sure we still form native strings from valid UTF-8 contents? The benchmarks will reflect this improvement as well. |
@milseman Rebased. |
@swift-ci please benchmark |
Build comment file: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
|
This doesn't really show the benefit because those benchmarks use Array, which wouldn't copy even in unspecialised generic code. Created #22277 to add benchmarks for UBP, URBP. The same should apply to |
Ok, do you know why there is a 41% regression when it is an array, though? |
Not yet, I'll check it out. I've found these benchmarks to be pretty noisy locally. In any case, I think we could speed it up a teeny bit more by copying to |
No description provided.