xds/clients: cache raw resource bytes internally for CSDS and remove Bytes() from ResourceData
Author: dashpoleCreated Sep 30, 2026Updated Sep 30, 2026
Use case(s) - what problem will this feature solve?
Consumer implementations of xdsclient.ResourceData are currently required to implement both Equal(other ResourceData) bool and Bytes() []byte.
The only caller of ResourceData.Bytes() in xdsclient is authority.go when building v3statuspb.ClientConfig_GenericXdsConfig for DumpResources() (CSDS). Because of this, every consumer Decoder is required to implement Bytes() []byte on its decoded domain struct solely to satisfy CSDS config dumping.
Proposed Solution
In xdsChannel.decodeResponse (channel.go), xdsclient already holds the raw serialized resource bytes (r.GetValue()) right before calling Decoder.Decode.
- Store the raw
[]bytedirectly onauthority's internalresourceStatealongsidecache ResourceDatafor CSDSDumpResources(). - Remove
Bytes() []bytefromResourceData:type ResourceData interface { Equal(other ResourceData) bool }
Alternatives Considered
Keeping Bytes() []byte on ResourceData:
- Downside of removing
Bytes()(memory trade-off for non-CSDS consumers): Forgrpc-go's built-in resource types (ListenerResourceData,RouteConfigResourceData,ClusterResourceData,EndpointsResourceData),Resource.Rawis already retained in memory onstate.cache(and used by theirEqual()implementations), so cachingraw []byteonresourceStatehas no net memory impact whenResource.Rawis removed. However, for external consumers that do not use CSDS (DumpResources()) and have large resources, they can currently returnnilfromBytes()so the raw protobuf bytes are garbage-collected afterDecode(). Ifauthorityunconditionally retainsraw []byteonresourceState, those raw bytes will remain in memory alongside the decodedResourceDatastruct unless CSDS byte caching is optional orBytes()is retained.
Additional Context
Part of #9455.
Source: grpc/grpc-go