-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[stdlib] Make Range.init(_: ClosedRange<Bound>) inlinable #40871
Conversation
Currently, a simple function such as: ```swift func makeSingleElementRange(n: Int) -> Range<Int> { return Range(n...n) } ``` will result in the following assembly under optimisation: ``` output.makeSingleElementRange(n: Swift.Int) -> Swift.Range<Swift.Int>: sub rsp, 40 mov qword ptr [rsp + 8], rdi mov qword ptr [rsp + 16], rdi call (lazy protocol witness table accessor for type Swift.Int and conformance Swift.Int : Swift.SignedInteger in Swift) mov rcx, rax mov rsi, qword ptr [rip + ($sSiN)@GOTPCREL] mov rdx, qword ptr [rip + ($sSiSxsWP)@GOTPCREL] lea rax, [rsp + 24] lea rdi, [rsp + 8] call ($sSnsSxRzSZ6StrideRpzrlEySnyxGSNyxGcfC)@plt mov rax, qword ptr [rsp + 24] mov rdx, qword ptr [rsp + 32] add rsp, 40 ret ``` Mark the `init` as inlinable so these functions can be properly optimised. Also add a missing line of documentation.
@swift-ci smoke test |
@swift-ci benchmark |
Performance (x86_64): -O
Code size: -OPerformance (x86_64): -Osize
Code size: -OsizePerformance (x86_64): -Onone
Code size: -swiftlibsHow 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
|
Is there anything else that's needed here? I assume the benchmark changes are spurious – I had a quick look and didn't spot anything that would obviously be affected by this change. |
@CodaFi Would you mind reviewing this or suggesting someone for review? |
Looks fine to me! |
⛵ |
Currently, a simple
Range.init(_: ClosedRange<Bound>)
-calling function such as:will perform unspecialised generic calls under optimisation because
Range.init(_: ClosedRange<Bound>)
is not inlinable:Mark the
init
as inlinable so these functions can be properly optimised.Also add a missing line of documentation.