-
Notifications
You must be signed in to change notification settings - Fork 1.6k
proto: streaming or scatter/gather API for wire encoding/decoding #912
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
Comments
This has impact on |
We still would like a fast streaming marshal/unmarshal API. I believe that CL/215719 abstracts the fast-path API enough that we can add streaming at a later time without needing to add new methods to the |
There are two incompatible approaches we can take to a streaming marshal/unmarshal API, which each come with their own tradeoffs. One is a streaming API, which does not require that all of the full encoded message be held in memory at once. This would allow you to, for example, marshal a gigabyte-large message to an The other is a scatter-gather API, which requires that the full encoded message be held in memory at once but does not require that it all be held in a single buffer. Essentially, this allows you to marshal to or from a Scatter-gather is simpler to implement efficiently and allows for some optimizations that are impossible in a streaming API. For example, a scatter-gather marshal implementation could avoid the need for a per-message size cache field by encoding messages back-to-front. There are obvious use cases for the full streaming API. (Marshaling that gigabyte-large message.) There are other cases where streaming is less useful than it might seem; for example, an RPC system which checks a signature on each received message before unmarshaling it probably needs to hold the entire encoded message in memory already. I am inclined to say that scatter/gather is the better tradeoff; more memory consumption (but no worse than we require today) is a fair trade for simpler code and better performance. |
I think real world usage of I think a full streaming API provides a very specific use case and purpose, which often gets in the way when people are just looking for the simple way to do something. |
It is worth noting that a streaming API also allows the integrator to implement scatter-gather using io.MultiReader and io.MultiWriter. |
Unfortunately, an The tradeoff is that a streaming API is more flexibile (as you point out, you can trivially convert a streaming operation to a scatter/gather one), but a more limited scatter/gather API is simpler to implement and enables performance optimizations that are difficult in the more general-purpose streaming API. |
Can you help me understand what kinds of efficiencies you're referring to? An example of an optimization that is possible with |
For one, a |
Was triaging the issue list and discovered that this is a duplicate of #609. Closing in favor of the older one. |
No description provided.
The text was updated successfully, but these errors were encountered: