-
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: small & medium sized string copies over 10% faster #640
Conversation
spurious test error
|
@swift-nio-bot test this please |
Sources/NIO/ByteBuffer-core.swift
Outdated
let newBytesPtr = UnsafeMutableRawBufferPointer(rebasing: self._slicedStorageBuffer | ||
.dropFirst(Int(index)) | ||
.prefix(capacity)) | ||
let newBytesPtr = UnsafeMutableRawBufferPointer(rebasing: self._slicedStorageBuffer[Int(index) ..< Int(index) &+ Int(capacity)]) |
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.
Why the unchecked addition? None of the others perform it.
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.
@Lukasa just to double check I understand you are talking about &+
(no overflow check) ?
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.
Correct
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.
I think I am generally fine with doing it here but if we do so we should also do it in other places where we are sure overflow can never happen to be consist. So maybe we should just not do it in this PR and then open another PR with only the "unchecked" stuff.
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.
I think this is mostly my point: if we believe the unchecked math here is safe we should a) do it more consistently, and b) put comments explaining why we think that, as we've done for force-unwrapping.
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 to me!
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.
benchmarks don't show that the &+
make a diff here, removing
Motivation: urbp[start ..< end] is quite a bit faster than when done in two operations urbp.dropFirst(start).prefix(length). This improves small (4 bytes) & medium sized (24 bytes) String copies by over 10%. Good for HTTP headers etc. Modifications: replace urbp.dropFirst(start).prefix(length) by urbp[start ..< start + length] Result: small & medium sized String copies faster
608dcc1
to
8c8a65a
Compare
Motivation:
urbp[start ..< end] is quite a bit faster than when done in two
operations urbp.dropFirst(start).prefix(length). This improves small (4
bytes) & medium sized (24 bytes) String copies by over 10%. Good for
HTTP headers etc.
Modifications:
replace urbp.dropFirst(start).prefix(length) by urbp[start ..< start +
length]
Result:
small & medium sized String copies faster