Skip to content

Reduce binary size#2238

Open
prestist wants to merge 4 commits into
coreos:mainfrom
prestist:reduce-binary-size
Open

Reduce binary size#2238
prestist wants to merge 4 commits into
coreos:mainfrom
prestist:reduce-binary-size

Conversation

@prestist

@prestist prestist commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

To see the size breakdown between 2.20.0 and 2.26.0 you can run this gist.

Feel free to compare to this branch as well by changing the var to HEAD.

Packages not in v2.20.0

Package Size Source
envoyproxy/go-control-plane +3.38 MB via GCS storage v1.50
aws/aws-sdk-go-v2 +3.32 MB replaced aws-sdk-go v1
AzureAD/microsoft-auth-library +0.30 MB via Azure SDK
cncf/xds +0.24 MB via GCS storage v1.50
opentelemetry.io/otel/sdk +0.22 MB via GCS storage v1.50
cloud.google.com/go/monitoring +0.18 MB via GCS storage v1.50
Azure/azure-sdk-for-go +0.17 MB Azure blob support
go-jose/go-jose +0.09 MB via spiffe
aws/smithy-go +0.09 MB via AWS SDK v2

Packages that have changed in size

Package v2.20 Current Delta
google.golang.org/grpc 0.34 MB 1.09 MB +0.75 MB
coreos/ignition 1.02 MB 1.12 MB +0.10 MB
google.golang.org/api 0.37 MB 0.45 MB +0.09 MB
google.golang.org/protobuf 0.77 MB 0.85 MB +0.08 MB

Size Change: Before and After PR

  Before After Delta
Binary 64.87 MB 20.73 MB -44.14 MB
Vendored packages 13.69 MB 2.71 MB -10.97 MB

See: #2045

prestist added 3 commits June 17, 2026 16:01
The cloud.google.com/go/storage library's transitive dependency tree
(envoyproxy, grpc, xds, opentelemetry) is the primary driver of
binary size growth. Replace with direct HTTP calls to the GCS JSON
API, using the existing HTTP fetcher and oauth2 token source.
Removes cloud.google.com/go/storage and transitive deps including
envoyproxy, grpc, cncf/xds, and opentelemetry. Binary size drops
from 65 MB to 21 MB.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the GCS client library with direct HTTP calls to the GCS JSON API, significantly reducing the binary size by removing heavy dependencies like cloud.google.com/go/storage and related libraries. While this is a great optimization, the new implementation introduces critical concurrency issues. Specifically, the lazy initialization of GCSTokenSource in fetchFromGCS is not thread-safe and can cause a data race when resources are fetched concurrently. Additionally, mutating opts.Headers directly poses a risk of concurrent map write panics if the options are shared across goroutines. Addressing these issues by using sync.Once for initialization and cloning the headers map will ensure a safe and robust implementation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/resource/url.go
Comment thread internal/resource/url.go
Comment thread internal/resource/url.go
@travier

travier commented Jun 19, 2026

Copy link
Copy Markdown
Member

Nice find. It got in via #2005.

@travier

travier commented Jun 19, 2026

Copy link
Copy Markdown
Member

Code seems OK but I only gave it a quick look. Do we have a test for that use case? It would be good to make sure we have one to ensure we don't regress here. Thanks!

@travier travier self-requested a review June 19, 2026 12:05
@jlebon

jlebon commented Jun 19, 2026

Copy link
Copy Markdown
Member

Very nice! I wonder if there's more low-hanging fruit here to tackle. Something an AI agent would probably be good at identifying.

@prestist

prestist commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Code seems OK but I only gave it a quick look. Do we have a test for that use case? It would be good to make sure we have one to ensure we don't regress here. Thanks!

We have kola tests for both auth'd https://github.com/coreos/fedora-coreos-config/blob/9b14cac40de19089d4362b960cb7d098fd523301/tests/kola/ignition/resource/authenticated-gs/config.bu

and anon fetching

https://github.com/coreos/fedora-coreos-config/blob/9b14cac40de19089d4362b960cb7d098fd523301/tests/kola/ignition/resource/remote/config.bu

Also just added some test coverage to verify form of our request ie..

  • URL translation from gs:// scheme to GCS JSON API format
  • Path escaping (slashes, spaces, special characters)
  • Auth header is attached when credentials exist
  • Auth header is absent when credentials don't exist
  • Response body flows through correctly

But we will need to still rely on the kola tests for actual fetch verification .. ie..

  • Real gs:// fetch against storage.googleapis.com on a GCE VM
  • Anonymous access to a public bucket
  • Authenticated access using a GCE service account

@prestist prestist force-pushed the reduce-binary-size branch from bb3c0d9 to 47a6c8e Compare June 23, 2026 16:05
Test URL construction (path escaping, query params) and end-to-end
fetch with httptest server verifying request path, auth headers,
and response body for anonymous, authenticated, and nested-path
cases. Also fix double-encoding of object paths by setting RawPath.

Co-Authored-By: Claude <noreply@anthropic.com>
@prestist prestist force-pushed the reduce-binary-size branch from 47a6c8e to 5a1f1d8 Compare June 23, 2026 18:16
@prestist

prestist commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Very nice! I wonder if there's more low-hanging fruit here to tackle. Something an AI agent would probably be good at identifying.

Definitely! I have already of a size breakdown of the remaining packages. The next packages I believe would be the AWS SDK (3.48 MB) and Azure SDK (0.51 MB), while I think it would be easy enough to determine what breaks from the CI, I still think it could be better to have them be separate PRs scoping them as separate improvements wdyt?

@prestist prestist marked this pull request as ready for review June 24, 2026 13:19
@tormath1

Copy link
Copy Markdown
Contributor

Out of scope, but I think it would be worth to investigate systemd-imds integration with Ignition to remove those vendors libraries: https://www.freedesktop.org/software/systemd/man/latest/systemd-imdsd@.service.html# (maybe open an issue on the Ignition repo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants