Go Protobuf's New Opaque API Improves Performance and Safety

2024-12-16

The Go team released a new Opaque API for Go Protobuf, coexisting with the existing Open Struct API. This new API decouples generated code from its underlying memory representation, leading to performance improvements, reduced memory allocations, and enabling optimizations like lazy decoding. By hiding struct fields and accessing them only through accessor methods, it prevents pointer-related bugs and accidental sharing. Migration involves enabling the Hybrid API, using the `open2opaque` tool, and then switching to the Opaque API. The existing Open Struct API remains supported.

(go.dev)
Development