Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid copying client interceptor contexts #1092

Merged

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jan 7, 2021

Motivation:

The client interceptor pipeline holds an array of interceptor contexts.
Each context is a struct and also holds a reference to the pipeline.
Each time the context asks the pipeline for the next inbound/outbound
context we incur a copy of the context which is surprisingly costly due
to retain and release traffic for the pipeline ref as well as the cost
of initializing the unspecialized contexts.

Modifications:

  • interceptor contexts now ask the pipeline to perform an operation for
    them rather than asking for a context on which to perform the
    operation, this avoids copying contexts
  • as the pipeline is now responsible for performing the operations a
    further optimisation is opened up: head and tail interceptors and
    contexts are no longer required, the same action can be done directly
    by the pipeline

Result:

A 4.8% reduction in instructions in the unary_10k_small_requests
benchmark.

Motivation:

The client interceptor pipeline holds an array of interceptor contexts.
Each context is a struct and also holds a reference to the pipeline.
Each time the context asks the pipeline for the next inbound/outbound
context we incur a copy of the context which is surprisingly costly due
to retain and release traffic for the pipeline ref as well as the cost
of initializing the unspecialized contexts.

Modifications:

- interceptor contexts now ask the pipeline to perform an operation for
  them rather than asking for a context on which to perform the
  operation, this avoids copying contexts
- as the pipeline is now responsible for performing the operations a
  further optimisation is opened up: head and tail interceptors and
  contexts are no longer required, the same action can be done directly
  by the pipeline

Result:

A 4.8% reduction in instructions in the unary_10k_small_requests
benchmark.
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Jan 7, 2021
@glbrntt glbrntt requested a review from Lukasa January 7, 2021 10:26
@glbrntt glbrntt merged commit befa21a into grpc:main Jan 7, 2021
@glbrntt glbrntt deleted the gb-avoid-copy-interceptor-context-client branch January 7, 2021 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants