-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Interfaces for supporting zero copy into Protobuf (HasByteBuffer & Detachable) #7387
Comments
This is a great step towards memory efficiency, @voidzcy, thank you What seems to be missing is a way to transfer ownership of detached buffers to the parsed message itself so they can be released for that message only when application code is done with it (without having to modify protoc-generated classes). This would be particularly handy with reactive-grpc With Marshaller holding indistinguishable references to all of them, from all invocations of RPC methods you can only release all of them at once it seems which is not particularly useful |
is zero-copy serialization being discussed anywhere, btw? |
You don't have to hold buffers until finishing all RPC invocations, you can release each time you finished using the current message. This is an advanced feature originally introduced to support some Google Cloud client usages, and we have not discussed or documented it publicly. If you are interested, you could look at the example usage in GoogleCloudPlatform/grpc-gcp-java#77. |
that's a simple but effective trick I didn't think of (map and popStream()), thank you |
I am interested in this too, especially in the context of using a Wondering if anyone else has thought of approaches for the serialization side. For reference, Armeria's able to use the fast path since it doesn't have buffer abstractions but for Netty, the pattern through gRPC's buffer abstractions would need to look the same, serialize into a ByteBuffer and update the writerIndex. |
@anuraaga, the writing path is discussed in the (long) #1054. Without reading through it too closely, I think this point might be a play to start reading: #1054 (comment) API review:
|
APIs for supporting zero-copy protobuf deserialization from ByteBuffers to protobuf messages. The marshaller can wrap ByteBuffer as ByteSting with UnsafeByteOperations, concatenate ByteStrings into a single RopeByteString and then create a CodedInputStream from it.
New interfaces for the inbound InputStream to allow the marshaller:
HasByteBuffer
: access the underlying ByteBuffers directly without copying bytesDetachable
: keep the ByteBuffers around until the application code is done with using the protobuf messages.More details and an example marshaller implementation can be seen in #8102 (comment).
The text was updated successfully, but these errors were encountered: