-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add ByteString ToReadOnlySpan #7487
Add ByteString ToReadOnlySpan #7487
Conversation
Hi, is this change worth having? if so, will add tests. |
LGTM - please add some tests |
Hi @Aaronontheweb ,PR Review please. |
Will do |
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.
LGTM
return new ReadOnlySpan<byte>(compactBuffer.Array, compactBuffer.Offset, compactBuffer.Count); | ||
} | ||
|
||
return new ReadOnlySpan<byte>(ToArray()); |
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.
Sucks that we have to allocate here but there's no way around it: Span<T>
requires units to be allocated contiguously
Fixes #7488
Changes
Add ByteString ToReadOnlySpan, which has
NO
memory copy, compared to ToArray(), when ByteString is compact.Why?
Currently we do a lot of RabbitMQ IncomingMessage Deserialization by calling ToArray() (which does memory copying)
Using ToReadOnlySpan, memory copy can be avoided, as most of our IncomingMessage is compact
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
Latest
dev
BenchmarksInclude data from the relevant benchmark prior to this change here.
This PR's Benchmarks
Include data from after this change here.