You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe it would have been better if they used a single bytes field and a separate type field, but I'm afraid the design is set in stone as the format is already widely used.
Suggested Goal
Unfortunately I don't understand the code well enough to provide a pull request, but this is how I would imagine the generated code to look like in order to fix the problem:
Inside the UnmarshalVT method, the code would look something like this; As a first step I'm only reusing the memory, if the Data field previously had the same type:
This suggested generated code seems reasonable to me, but I do feel like it's gonna be tough to implement. We can merge this improvement if you get it working, and I think you're in the right direction. The right way to tackle this is starting with the generated code you're expecting to see and then tweaking the codegen until you get the desired results. :)
I'm afraid my pain is not high enough to attempt implementing the feature at the moment. Maybe I will find more motivation in the future. I'll leave it to you to close this issue for now or keep it open.
Problem
When using pools, the
ResetVT
method is able to reuse allocated memory of bytes. It looks like this with a minimal example:When the bytes are inside a
oneof
field, the memory is no longer reused:Use Case
This is a real problem for me when parsing open streetmap's PBF files, because they use this construct for large blobs of data that occur hundreds to thousands of times in a PBF file: https://github.com/openstreetmap/OSM-binary/blob/65e7e976f5c8e47f057a0d921639ea8e6309ef06/osmpbf/fileformat.proto#L38
Maybe it would have been better if they used a single
bytes
field and a separatetype
field, but I'm afraid the design is set in stone as the format is already widely used.Suggested Goal
Unfortunately I don't understand the code well enough to provide a pull request, but this is how I would imagine the generated code to look like in order to fix the problem:
Inside the
UnmarshalVT
method, the code would look something like this; As a first step I'm only reusing the memory, if theData
field previously had the same type:The text was updated successfully, but these errors were encountered: