c++ gRPC library compiled size - reasonable opportunities for reduction

519 views
Skip to first unread message

Kyle Loveless

unread,
Apr 29, 2023, 12:56:36 AM4/29/23
to grpc.io
Hey folks,

Just curious if there is a current opinion about opportunities to make gRPC a smaller final library - with or without symbols.

Using bloaty, my C++ server, which uses gRPC, has ~2.4MiB of VM size from it (not including other dependencies, like proto or SSL), and 59.4MB of file size (the difference being debug symbols, if not stripped). While ~2.4MiB doesn't seem too bad, the debug symbols are bit hefty.

I poked around a bit, and I suspect there is some opportunity for additional compile options so more can be dropped at link time. For instance:
  • Several types of credentials, even though maybe only a small subset are used. e.g. src/core/lib/security/credentials/external/aws_external_account_credentials.cc uses 32KiB of VM, and 476Ki with symbols. Presumably this only applies for certain users, and not in my case, but is kept during linking since it is not known it won't come up.
  • All of the load balancing policies are linked in, even though maybe only a small subset are used. rls/ is 95Ki of VM, 2.7MiB with symbols), outlier detection is 30 KiB of VM, 914KiB with symbols.
And of course, everything is a trade-off - more options means more variations for users and possible confusion.

Thoughts? Are there possible options that folks that could opt-in that could lead to significant reductions to make it worth it?

Thanks!

Kyle

Kyle Loveless

unread,
May 4, 2023, 11:22:52 AM5/4/23
to grpc.io
In case it's useful to others, I dropped the size in my compiled binary from 2.4Mi to 2Mi by:
  • Not including //src/core:grpc_external_account_credentials (with minor function changes not to try it)
  • Not including any of the load balancers I was not using (PickFirst is the default)
  • Removing the grpc_resolver_dns_ares (with a small number of code changes)
  • Also RegisterFakeResolver, RegisterHttpProxyMapper, FaultInjectionFilterRegister
This was done just with an unconditional local patch for now.

veb...@google.com

unread,
May 4, 2023, 7:19:39 PM5/4/23
to grpc.io
Hey Kyle,

gRPC C++ doesn't have many knobs to reduce the footprint. One option you can try is "--define=grpc_no_xds=true" for bazel. Unfortunately, this option isn't available for cmake but you can take a look at what can be removed by this option since you've made local changes already.

Regards,
Esun.

Reply all
Reply to author
Forward
0 new messages