Skip to content

perf(grpc-js): avoid allocations for empty CallCredentials on the RPC hot path - #3100

Open
olavloite wants to merge 1 commit into
grpc:masterfrom
olavloite:avoid-empty-credentials-allocation
Open

olavloite wants to merge 1 commit into
grpc:masterfrom
olavloite:avoid-empty-credentials-allocation

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Previously, every RPC executed through LoadBalancingCall composed per-call and subchannel CallCredentials and called generateMetadata(), even when both sides were EmptyCallCredentials. In addition:

  • Composing any CallCredentials with EmptyCallCredentials on the right-hand side wrapped them in a new ComposedCallCredentials instance.
  • InsecureChannelCredentialsImpl allocated a new EmptyCallCredentials instance on every getCallCredentials() call when no call credentials were provided.
  • EmptyCallCredentials.generateMetadata() allocated a new Metadata instance and Promise on every RPC only to merge an empty map.

This change:

  • Treats EmptyCallCredentials as a two-sided identity in compose(), returning this directly when composing with an empty instance.
  • Evaluates the fallback CallCredentials.createEmpty() once per connector in InsecureChannelCredentialsImpl._createSecureConnector().
  • Short-circuits metadata generation and merging in LoadBalancingCall when the composed CallCredentials is empty, reusing a pre-resolved Promise.

… hot path

Previously, every RPC executed through LoadBalancingCall composed per-call
and subchannel CallCredentials and called generateMetadata(), even when both
sides were EmptyCallCredentials. In addition:
- Composing any CallCredentials with EmptyCallCredentials on the right-hand
  side wrapped them in a new ComposedCallCredentials instance.
- InsecureChannelCredentialsImpl allocated a new EmptyCallCredentials instance
  on every getCallCredentials() call when no call credentials were provided.
- EmptyCallCredentials.generateMetadata() allocated a new Metadata instance
  and Promise on every RPC only to merge an empty map.

This change:
- Treats EmptyCallCredentials as a two-sided identity in compose(), returning
  `this` directly when composing with an empty instance.
- Evaluates the fallback CallCredentials.createEmpty() once per connector in
  InsecureChannelCredentialsImpl._createSecureConnector().
- Short-circuits metadata generation and merging in LoadBalancingCall when the
  composed CallCredentials is empty, reusing a pre-resolved Promise.
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.

3 participants