grafana / pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
https://grafana.com/oss/pyroscope/
GNU Affero General Public License v3.0
9.65k stars 576 forks source link

Connect: Use custom codec for vtproto #3310

Closed simonswine closed 1 month ago

simonswine commented 1 month ago

This implements a custom codec for use with connect-go. It uses the vtproto provided methods UnmarhsalVT rather than the upstream protobuf decoder/encoder.

simonswine commented 1 month ago

While I don't think this lead to significant shift in performance, it brings makes us use the benefits of vtprotobuf for the proto that are marshalled/unmarshalled from/for requests.

func (p *YourProto) MarshalVT() ([]byte, error): this function behaves identically to calling proto.Marshal(p), except the actual marshalling has been fully unrolled and does not use reflection or allocate memory. This function simply allocates a properly sized buffer by calling SizeVT on the message and then uses MarshalToSizedBufferVT to marshal to it.
unmarshal: generates a func (p *YourProto) UnmarshalVT(data []byte) that behaves similarly to calling proto.Unmarshal(data, p) on the message, except the unmarshalling is performed by unrolled codegen without using reflection and allocating as little memory as possible. If the receiver p is not fully zeroed-out, the unmarshal call will actually behave like proto.Merge(data, p). This is because the proto.Unmarshal in the ProtoBuf API is implemented by resetting the destination message and then calling proto.Merge on it. To ensure proper Unmarshal semantics, ensure you've called proto.Reset on your message before calling UnmarshalVT, or that your message has been newly allocated.

https://github.com/planetscale/vtprotobuf/blob/615f978279caa2965ae5d57c7d242f88b38e6802/README.md?plain=1#L21-L38

simonswine commented 1 month ago

No, I only deployed it to the distributors in ops.

image