#9460·grpc-go

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.

  1. Store the raw []byte directly on authority's internal resourceState alongside cache ResourceData for CSDS DumpResources().
  2. Remove Bytes() []byte from ResourceData:
    go
    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): For grpc-go's built-in resource types (ListenerResourceData, RouteConfigResourceData, ClusterResourceData, EndpointsResourceData), Resource.Raw is already retained in memory on state.cache (and used by their Equal() implementations), so caching raw []byte on resourceState has no net memory impact when Resource.Raw is removed. However, for external consumers that do not use CSDS (DumpResources()) and have large resources, they can currently return nil from Bytes() so the raw protobuf bytes are garbage-collected after Decode(). If authority unconditionally retains raw []byte on resourceState, those raw bytes will remain in memory alongside the decoded ResourceData struct unless CSDS byte caching is optional or Bytes() is retained.

Additional Context

Part of #9455.