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 server interceptor context #1090

Merged
merged 2 commits into from
Jan 6, 2021

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jan 6, 2021

Motivation:

The server 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:

  • An 11.2% reduction in instructions in the
    embedded_server_unary_10k_small_requests benchmark

Motivation:

The server 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:

- An 11.2% reduction in instructions in the
  embedded_server_unary_10k_small_requests benchmark
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Jan 6, 2021
@glbrntt glbrntt requested a review from Lukasa January 6, 2021 14:42
@glbrntt glbrntt requested a review from Lukasa January 6, 2021 17:10
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shiny, I love it.

@glbrntt glbrntt merged commit 6d04876 into grpc:main Jan 6, 2021
@glbrntt glbrntt deleted the gb-avoid-copying-interceptor-context branch January 6, 2021 18:24
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