Skip to content
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

How to support zero copy when decode the message ? #7899

Closed
runzhiwang opened this issue Sep 21, 2020 · 1 comment
Closed

How to support zero copy when decode the message ? #7899

runzhiwang opened this issue Sep 21, 2020 · 1 comment
Assignees
Labels

Comments

@runzhiwang
Copy link

runzhiwang commented Sep 21, 2020

What language does this apply to?

proto3, java

Describe the problem you are trying to solve.

My request is similar to https://groups.google.com/g/protobuf/c/ZaDigptdcHM

Currently, when read ByteString.readBytes, the order is InputStream -> StreamDecoder.buffer with 4kB size -> copy StreamDecoder.buffer to byte array on heap. Can we change the order to InputStream -> byte array on heap directly ? Besides, instead use byte array on heap, can we use byte array off-heap ?

As the image shows, arraycopy in StreamDecoder.readBytesSlowPath really cost too much CPU. I want to improve it by avoid arraycopy. If there is other suggestions, I would appreciate it, thank you very much.

image

@runzhiwang runzhiwang changed the title Zero copy when decode the message. How to zero copy when decode the message. Sep 21, 2020
@runzhiwang runzhiwang changed the title How to zero copy when decode the message. How to zero copy when decode the message ? Sep 21, 2020
@runzhiwang runzhiwang changed the title How to zero copy when decode the message ? How to support zero copy when decode the message ? Sep 22, 2020
@deannagarcia deannagarcia self-assigned this Oct 22, 2020
@deannagarcia
Copy link
Member

As explained in the comment you linked, unfortunately it is impossible to return the byte array directly because it must be copied to guarantee immutability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants