-
Notifications
You must be signed in to change notification settings - Fork 27
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
AMQP: Avoid allocating a new ByteString on each consumed message #592
base: main
Are you sure you want to change the base?
Conversation
Thanks @dimamo5 but I am not sure that this is necessarily a good idea. How can we be sure that AMQP provider does not reuse byte arrays? We can only use fromArrayUnsafe if we are 100% sure that the byte array won't be reused. Even if 1 AMQP solution can be proved not to reuse arrays, can we be sure that all AMQP solutions don't? |
The critical bit is the implementation of Regarding the AMQP provider, I don't think this connector allows for customization of the |
RabbitMQ is not the only AMQP implementation. We could make the ByteString behaviour configurable but I don't think we can hardcore this change. |
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.
Blocking merge while this change is debated.
Changes the ByteString constructor to a `fromArrayUnsafe`. It should be safe to use this unsafe method as long as `body` is to exposed to the outside.
9378b86
to
12ee76d
Compare
@dimamo5 I added an If this approach is ok, new tests will need to be added - that test with avoidArrayCopy=true. |
@pjfanning sorry for the slow response. This is what I was looking for. Thank you. |
@dimamo5 I've added code so that message writing can also avoid copying the array data for the ByteStrings - also based on I'm pretty busy with other Pekko stuff. Would you have time to add some test cases that say duplicate existing test cases for read and write cases but where |
Avoids copying a new array and a new allocation by using the
fromArrayUnsafe
method. It should be ok to build from this unsafe method as long asbody
is not exposed to the outside.