golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.72k stars 1.58k forks source link

protoc-gen-go: use pointer for unknownFields #858

Open dsnet opened 5 years ago

dsnet commented 5 years ago

(Background: #856)

XXX_unrecognized is the internal field used to implement unknown fields. The current type is a []byte, which occupies 24B on 64-bit systems. However, the vast majority of situations do not have any unknown fields to store, so this is an increase of 24B that is mostly useless.

Consider changing this to be a pointer instead (perhaps *[]byte), to reduce the footprint to 8B.

tandr commented 5 years ago

@dsnet sorry if this is a something you have already thought about, I am not familiar with new code base.

There are whole lot of XXX fluff in a current protobuf, maybe bite the bullet and offload all of them into _xxx *ProtoMeta special struct (and add "GetXXX() *..." call). Or export it, but then you can accidentally set it, not sure if this is an intention.

dsnet commented 5 years ago

Variations of what you suggest is already implemented in v2. The v2 generator does not emit any XXX fields or methods.