protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.56k stars 15.48k forks source link

Add C# codegen for Clear message to reuse message objects in a pool #18782

Open batesj opened 2 weeks ago

batesj commented 2 weeks ago

What language does this apply to? C# codegen.

Describe the problem you are trying to solve. Using protobufs in Unity can cause excessive garbage collection overhead because of all the new class instances created while parsing a proto into a message instance.

Describe the solution you'd like I would like to be able to reuse a pool of message instances repeatedly for parsing protos.

Describe alternatives you've considered I could not find examples, but perhaps there is a way to do it with reflection? Of course, if that's expensive then it is replacing garbage with CPU overhead.

ifshuaishuai commented 4 days ago

In game developing area, especially in unity, recycle message object from pool is a must-have. I'm current looking for same Clear() method like PB did for Java for recycling.