-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
[C#] Enable pooling of messages with large RepeatedFields #7828
Comments
Reassigning this as I'm not on the protobuf team - but this sort of pooling sounds pretty complicated to achieve. |
I agree with Jon, this pooling sounds complicated. We've generally gotten good results from using arenas -- if anything we'd probably be more inclined to go in that direction. |
Hey @haberman would you consider re-opening this and possibly accepting a PR? I don't think the ask was for protobuf to implement pooling. It was to do something like this... public void Clear()
=> Clear(emptyArray: true);
public void Clear(bool emptyArray = true)
{
array = emptyArray ? EmptyArray : array;
count = 0;
} This would allow users to implement their own pooling of For comparison, runtime |
@CodeBlanch: I don't think that's actually what was being requested. The first comment explicitly says:
Each message has a separate If the OP was talking about reusing the original message by clearing and re-populating it, that would be different (and certainly more feasible) - but that's not what's been asked for at the moment. |
@CodeBlanch @jskeet apologies for the unclear initial issue description. The intention of the issue was pretty much exactly what @CodeBlanch interpreted. Instead of
Should have written something like
By now the performance of my use case is good enough for me (through other means), so I personally don't have any need for this change. But @CodeBlanch feel free to hijack this issue :-) |
Okay, so the proposed change would just be to the |
FWIW, there is prior art for this kind of optimization in C++ protobuf. |
That would work for me 👍 Happy to submit a PR if it would be helpful. |
@CodeBlanch: Nope, it's fine - I'll try to get round to it soon. It won't be hard, it's just a matter of finding time. |
Fixes protocolbuffers#7828. (Also tweaks the comment for Capacity.)
What language does this apply to?
C# proto3
Describe the problem you are trying to solve.
Sending multiple messages, each containing a large
RepeatedField
(all of the same size), without allocating a new backing array for eachRepeatedField
. Effectively, I'd like to be able to poolRepeatedFields
for reuse.Describe the solution you'd like
One possible solution could be to provide a method similar to
Clear
, which keeps the backing array and only resets thecount
field (see here).The text was updated successfully, but these errors were encountered: