Repository navigation
discovery/gce: keep Compute SD client from defeating dead-code eliminationation - #18819
Merged
roidelapluie merged 1 commit intoMay 29, 2026
Merged
Conversation
roidelapluie
force-pushed
the
roidelapluie/gce-sd-binary-size
branch
from
May 29, 2026 11:56
fd4a5eb to
eaf30be
Compare
…ation The Discovery struct held *compute.Service and *compute.InstancesService as fields and is boxed into the discovery.Discoverer interface. Once reflection is reachable in the program (it always is, via the YAML/config machinery), the Go linker conservatively retains every exported method of any concrete type reachable through an interface, including via struct fields. *compute.Service exposes ~150 sub-services and their operations, so all of them — 994 list/get operations and their serializers — were retained even though discovery only calls Instances.List. Wrap the single used operation in a closure over the concrete *compute.Service so the service lives only in closure context, which reflection cannot traverse. Returning a *compute.InstancesListCall would not help, since that type has an s *Service back-reference that re-propagates the marker, so the closure encapsulates the whole List/Filter/Pages chain and only exposes the *compute.InstanceList data type discovery already uses. compute/v1 footprint drops from ~4.9 MB to ~33 KB, and the prometheus and promtool binaries each shrink by ~13.5 MB. No functional or API change. Signed-off-by: Julien Pivotto <[email protected]>
roidelapluie
force-pushed
the
roidelapluie/gce-sd-binary-size
branch
from
May 29, 2026 12:00
eaf30be to
fd493fe
Compare
roidelapluie
enabled auto-merge
May 29, 2026 12:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Discovery struct held *compute.Service and *compute.InstancesService as fields and is boxed into the discovery.Discoverer interface. Once reflection is reachable in the program (it always is, via the YAML/config machinery), the Go linker conservatively retains every exported method of any concrete type reachable through an interface, including via struct fields. *compute.Service exposes ~150 sub-services and their operations, so all of them — 994 list/get operations and their serializers — were retained even though discovery only calls Instances.List.
Wrap the single used operation in a closure over the concrete *compute.Service so the service lives only in closure context, which reflection cannot traverse. Returning a *compute.InstancesListCall would not help, since that type has an s *Service back-reference that re-propagates the marker, so the closure encapsulates the whole List/Filter/Pages chain and only exposes the *compute.InstanceList data type discovery already uses.
compute/v1 footprint drops from ~4.9 MB to ~33 KB, and the prometheus and promtool binaries each shrink by ~13.5 MB. No functional or API change.
Which issue(s) does the PR fix:
Release notes for end users (ALL commits must be considered).
Reviewers should verify clarity and quality.