Skip to content

Optimize RawSpan/_extracting methods #82057

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oscbyspro
Copy link
Contributor

Use bit casting operations to remove branches in:

  • RawSpan/_extracting(last:)
  • RawSpan/_extracting(droppingFirst:)
  • RawSpan/_extracting(unchecked:)

See also: #81902

This pull request is a practical example: @stephentyrone

Comments

Note that this optimization relies on Int.init(bitPattern:) and UnsafeRawPointer.init?(bitPattern:) being branchless. They are not branchless at the time of writing. This contribution is but one part of an attempt to fix that.

- `RawSpan/_extracting(last:)`
- `RawSpan/_extracting(droppingFirst:)`
- `RawSpan/_extracting(unchecked:)`
@oscbyspro oscbyspro changed the title Optimize some RawSpan/_extracting methods Optimize RawSpan/_extracting methods Jun 6, 2025
@stephentyrone
Copy link
Contributor

stephentyrone commented Jun 6, 2025

Generally speaking, we want to resolve these sorts of issues in SIL/LLVM if possible, rather than littering unsafeBitCast everywhere. If that turns out to be impossible for some reason or another, we can resort to bit casts, but we should be starting with that.

CC @glessard, @meg-gupta

@oscbyspro
Copy link
Contributor Author

I'll be here to pick up the slack when SIL and LLVM tap out 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants