google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

storage: shipping extra 8MB with github.com/envoyproxy/go-control-plane/envoy

Open dbaroncelli opened this issue 7 months ago • 3 comments

Environment

go version go1.24.3 linux/amd64

Expected behavior

We are building our golang binary with ldflags -w -s IT used to be around 24 MB.

Actual behavior

After we upgraded to firebase.google.com/go/v4 v4.15.2, which includes cloud.google.com/go/storage v1.50.0 (previous storage version was v1.39.1), we are seeing a big import of this package: github.com/envoyproxy/go-control-plane/envoy which adds extra 8.1 MB, which is over 30% binary size increase

It seems it's imported by cloud.google.com/go/storage.

go mod why -m github.com/envoyproxy/go-control-plane/envoy ourpackage firebase.google.com/go/v4 firebase.google.com/go/v4/storage cloud.google.com/go/storage google.golang.org/grpc/xds/googledirectpath google.golang.org/grpc/xds/internal/xdsclient github.com/envoyproxy/go-control-plane/envoy/admin/v3

Are you planning to minimize the size of this dependency? According to the package naming, it seems admin code rather than core code.

dbaroncelli avatar May 28 '25 11:05 dbaroncelli

Hi @dbaroncelli, thank you for opening an issue!

The envoyproxy package is required for direct connectivity. If you do not use gRPC, use the build tag disable_grpc_modules to opt out of these dependencies and reduce the binary size; see https://pkg.go.dev/cloud.google.com/go/storage#hdr-gRPC_API

Does that resolve the issue for you?

BrennaEpp avatar May 28 '25 22:05 BrennaEpp

I have made the build with -tags=disable_grpc_modules and it indeed reduces the binary size a lot: from 35MB, it became 23MB!

These are the package size differences (calculated by go-size-analyzer)

Image



Considering the massive difference in the binary size, I wonder if there isn't a better way to exclude these extra MB. I am just importing the package firebase.google.com/go/v4 I am not even importing directly firebase.google.com/go/v4/storage or cloud.google.com/go/storage. How would I know if the firebase functions I call need to use gRPC or not?

So, can you confirm that, whether or not I call a firebase function that uses gRPC, such big package is imported as well, unless I explicitely add -tags=disable_grpc_modules to the build?

I would expect there is a better mechanism to avoid importing packages that are not needed.

dbaroncelli avatar May 28 '25 22:05 dbaroncelli

So, can you confirm that, whether or not I call a firebase function that uses gRPC, such big package is imported as well, unless I explicitely add -tags=disable_grpc_modules to the build?

This is correct.

We will discuss with the Firebase team to see if there is a better solution for their users. Thank you for bringing attention to this issue.

BrennaEpp avatar Jun 09 '25 22:06 BrennaEpp

Hey, I got the same issue with spanner. It also using envoy there, but no option to disable RPC modules.

giautm avatar Jun 18 '25 15:06 giautm

Hi @giautm, please open another issue for Spanner

BrennaEpp avatar Jun 19 '25 21:06 BrennaEpp

I am closing this issue for now, but know that it is still on our radar. If you feel strongly about this and want a tracking issue, please open one for Firebase, as changes, if any, will need to be done in the Firebase package.

For Storage, the performance benefit of including these dependencies outweighs the cons of the size for a lot of users, so by default we include them, and provide a documented opt-out for those it doesn't.

BrennaEpp avatar Jul 03 '25 05:07 BrennaEpp