-
Notifications
You must be signed in to change notification settings - Fork 25
Code inlining #192
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
Open
rnro
wants to merge
6
commits into
apple:main
Choose a base branch
from
rnro:code-inlining
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−127
Open
Code inlining #192
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d2791c2
SwiftQUIC: Reduce the cost of packet number encoding
rnro e05f403
SwiftQUIC: Keep cold diagnostics out of small hot functions
rnro 38f947e
SwiftQUIC: Stop injecting the cross-span fallback into every field write
rnro 28347d8
SwiftQUIC: Route the ack bitstring diagnostics out of line
rnro cd60000
formatting
rnro d331ffe
Name the log category in the outlined reporting helpers
rnro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,7 +194,7 @@ public struct Deserializer<Factory: DeserializerSpanFactory & ~Copyable & ~Escap | |
| /// | ||
| /// Call this method when `hasRoom` fails but `internalResult` is still valid. | ||
| @inlinable | ||
| @inline(always) | ||
| @inline(never) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why never here? |
||
| mutating func readFragmented<T: BitwiseCopyable>(_ value: inout T) throws(DeserializationError) { | ||
| let length = MemoryLayout<T>.size | ||
| precondition(length <= 16) | ||
|
|
@@ -715,6 +715,45 @@ public struct Deserializer<Factory: DeserializerSpanFactory & ~Copyable & ~Escap | |
| moveCursorUnchecked(length) | ||
| } | ||
|
|
||
| /// Compares across span boundaries, refilling from the factory as each span is exhausted. | ||
| @usableFromInline | ||
| @inline(never) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why inlined never here if the calling function is inlined? |
||
| mutating func spanExpectFragmented(expect value: RawSpan, length: Int) throws(DeserializationError) { | ||
| // Fast fail if total available bytes across all spans is insufficient | ||
| guard availableByteCount - totalBytesParsed >= length else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
|
|
||
| var matched = 0 | ||
| while matched < length { | ||
| let available = min(remaining, length - matched) | ||
| if available > 0 { | ||
| let matches = value.withUnsafeBytes { expectedBytes in | ||
| let slice = UnsafeRawBufferPointer( | ||
| start: expectedBytes.baseAddress! + matched, | ||
| count: available | ||
| ) | ||
| return Deserializer.valueMatches( | ||
| lhs: slice, | ||
| rhs: currentSpan, | ||
| rhsOffset: cursor, | ||
| count: available | ||
| ) | ||
| } | ||
| guard matches else { | ||
| try invalidate(.validationFailed) | ||
| } | ||
| try moveCursor(available) | ||
| matched += available | ||
| } | ||
| if matched < length { | ||
| guard refill() else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @inlinable | ||
| @inline(always) | ||
| public mutating func span(expect value: RawSpan) throws(DeserializationError) { | ||
|
|
@@ -724,40 +763,7 @@ public struct Deserializer<Factory: DeserializerSpanFactory & ~Copyable & ~Escap | |
| } | ||
|
|
||
| guard hasRoom(length) else { | ||
| // Fast fail if total available bytes across all spans is insufficient | ||
| guard availableByteCount - totalBytesParsed >= length else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
|
|
||
| // Compare across span boundaries | ||
| var matched = 0 | ||
| while matched < length { | ||
| let available = min(remaining, length - matched) | ||
| if available > 0 { | ||
| let matches = value.withUnsafeBytes { expectedBytes in | ||
| let slice = UnsafeRawBufferPointer( | ||
| start: expectedBytes.baseAddress! + matched, | ||
| count: available | ||
| ) | ||
| return Deserializer.valueMatches( | ||
| lhs: slice, | ||
| rhs: currentSpan, | ||
| rhsOffset: cursor, | ||
| count: available | ||
| ) | ||
| } | ||
| guard matches else { | ||
| try invalidate(.validationFailed) | ||
| } | ||
| try moveCursor(available) | ||
| matched += available | ||
| } | ||
| if matched < length { | ||
| guard refill() else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
| } | ||
| } | ||
| try spanExpectFragmented(expect: value, length: length) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -771,6 +777,38 @@ public struct Deserializer<Factory: DeserializerSpanFactory & ~Copyable & ~Escap | |
| moveCursorUnchecked(length) | ||
| } | ||
|
|
||
| /// Reads across span boundaries directly into the destination. | ||
| @usableFromInline | ||
| @inline(never) | ||
| mutating func spanFragmented( | ||
| _ value: inout MutableSpan<UInt8>, | ||
| lengthToCopy: Int | ||
| ) throws(DeserializationError) { | ||
| var filled = 0 | ||
| while filled < lengthToCopy { | ||
| let available = min(remaining, lengthToCopy - filled) | ||
| if available > 0 { | ||
| let source = currentSpan.extracting(unchecked: cursor..<(cursor &+ available)) | ||
| source.withUnsafeBytes { fromBuffer in | ||
| value.withUnsafeMutableBytes { toBuffer in | ||
| let dest = UnsafeMutableRawBufferPointer( | ||
| start: toBuffer.baseAddress! + filled, | ||
| count: available | ||
| ) | ||
| dest.copyMemory(from: fromBuffer) | ||
| } | ||
| } | ||
| try moveCursor(available) | ||
| filled += available | ||
| } | ||
| if filled < lengthToCopy { | ||
| guard refill() else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @_optimize(speed) | ||
| @inlinable | ||
| @inline(always) | ||
|
|
@@ -790,30 +828,7 @@ public struct Deserializer<Factory: DeserializerSpanFactory & ~Copyable & ~Escap | |
| } | ||
|
|
||
| guard hasRoom(lengthToCopy) else { | ||
| // Read across spans directly into the destination | ||
| var filled = 0 | ||
| while filled < lengthToCopy { | ||
| let available = min(remaining, lengthToCopy - filled) | ||
| if available > 0 { | ||
| let source = currentSpan.extracting(unchecked: cursor..<(cursor &+ available)) | ||
| source.withUnsafeBytes { fromBuffer in | ||
| value.withUnsafeMutableBytes { toBuffer in | ||
| let dest = UnsafeMutableRawBufferPointer( | ||
| start: toBuffer.baseAddress! + filled, | ||
| count: available | ||
| ) | ||
| dest.copyMemory(from: fromBuffer) | ||
| } | ||
| } | ||
| try moveCursor(available) | ||
| filled += available | ||
| } | ||
| if filled < lengthToCopy { | ||
| guard refill() else { | ||
| try invalidate(.bufferTooShort) | ||
| } | ||
| } | ||
| } | ||
| try spanFragmented(&value, lengthToCopy: lengthToCopy) | ||
| return | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!