Skip to content

client: replace net/rpc with lightweight gob-based RPC client#191

Open
sverdlov93 wants to merge 2 commits into
googleapis:mainfrom
sverdlov93:remove-netrpc-dependency
Open

client: replace net/rpc with lightweight gob-based RPC client#191
sverdlov93 wants to merge 2 commits into
googleapis:mainfrom
sverdlov93:remove-netrpc-dependency

Conversation

@sverdlov93

Copy link
Copy Markdown

Summary

net/rpc is deprecated (frozen since Go 1.20) and imports html/template via its debug HTTP handler. html/template calls reflect.Value.MethodByName, which disables the Go linker's method dead code elimination (DCE) optimization for any binary that transitively imports this package.

This affects all users of google-api-go-client and cloud.google.com/go libraries, as they pull in enterprise-certificate-proxy as a dependency — even when enterprise certificates are not used.

Datadog reported up to 20% binary size reduction from enabling DCE, and the Kubernetes project saw 16–37% reductions on their binaries.

Changes

  • Added rpclite.go: a minimal gob-based RPC client (~60 lines of logic) that speaks the exact same wire protocol as net/rpc (gob-encoded Request/Response headers)
  • Updated client.go to use rpclite instead of net/rpc
  • No changes to the signer subprocess side — full backward compatibility

Wire protocol compatibility

The request and response structs in rpclite.go mirror net/rpc.Request and net/rpc.Response field-for-field, so gob encoding produces identical bytes. Existing signer binaries (which use net/rpc server) work without any changes.

Test plan

  • go test ./client/... — all existing tests pass
  • go list confirms net/rpc is no longer in the dependency tree
  • go build ./client/... compiles cleanly

net/rpc is deprecated (frozen since Go 1.20) and imports html/template
via its debug HTTP handler. html/template triggers reflect.MethodByName
which disables the Go linker's method dead code elimination (DCE)
optimization for any binary that transitively imports this package.

This affects all users of google-api-go-client and cloud.google.com/go
libraries, as they pull in enterprise-certificate-proxy as a dependency.
Datadog reported up to 20% binary size reduction from enabling DCE
(https://www.datadoghq.com/blog/engineering/agent-go-binaries/), and the
Kubernetes project saw 16-37% reductions.

The fix replaces net/rpc.Client with a minimal gob-based RPC client
(rpclite.go) that speaks the exact same wire protocol. This maintains
full compatibility with existing signer subprocesses — only the client
side changes, and the on-wire encoding (gob-encoded Request/Response
headers) is identical.

Tests pass with no changes required.
@google-cla

google-cla Bot commented Mar 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Tests verify that rpclite speaks the same gob-based wire protocol
as net/rpc by connecting an rpclite client to a real net/rpc server
over in-memory pipes.
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.

1 participant