-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ByteBuffer: one fewer allocs to go to Data #1839
Merged
Merged
Conversation
This file contains 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
Lukasa
requested changes
Apr 30, 2021
@@ -25,37 +26,39 @@ func run(identifier: String) { | |||
@inline(never) | |||
func doWrites(buffer: inout ByteBuffer) { | |||
/* these ones are zero allocations */ | |||
// buffer.writeBytes(foundationData) // see SR-7542 |
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 gone on purpose?
buffer.writeBytes([0x41]) | ||
buffer.writeBytes("A".utf8) | ||
buffer.writeString("A") | ||
buffer.writeStaticString("A") | ||
buffer.writeInteger(0x41, as: UInt8.self) | ||
|
||
/* those down here should be one allocation each (on Linux) */ | ||
buffer.writeBytes(dispatchData) // see https://bugs.swift.org/browse/SR-9597 |
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.
Similarly, is this gone on purpose?
2f6d36d
to
ada6eec
Compare
Lukasa
approved these changes
Jun 1, 2021
We should resurrect this |
aadf0d2
to
e7666f6
Compare
Motivation: When getting a `Data` from a `ByteBuffer` we currently allocate twice (`__DataStorage`) and the closure for `Data.Deallocator`. Modifications: We can optimise that by making the closure capture exactly one `AnyObject` which is already a reference counted object. The compiler realises that (on Linux) and saves us an alloc. Thanks @Lukasa for the suggestion here: apple#1836 (comment) Result: Fewer allocs.
e7666f6
to
a2f1a8f
Compare
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
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.
Motivation:
When getting a
Data
from aByteBuffer
we currently allocate twice(
__DataStorage
) and the closure forData.Deallocator
.Modifications:
We can optimise that by making the closure capture exactly one
AnyObject
which is already a reference counted object. The compilerrealises that (on Linux) and saves us an alloc.
Thanks @Lukasa for the suggestion here: #1836 (comment)
Result:
Fewer allocs.