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

Don't construct unnecessary buffers. #925

Merged
merged 1 commit into from
Aug 7, 2020

Conversation

Lukasa
Copy link
Collaborator

@Lukasa Lukasa commented Aug 7, 2020

Motivation:

Currently the HTTP1ToGRPCServerCodec constructs a CircularBuffer that it
only ever uses when doing grpc-web work. This is not the end of the
world, except that CircularBuffers require memory allocations: there is
no such thing as an empty CircularBuffer.

In general it's not a great idea to force the mainline grpc use-case to
pay for the cost of constructing a circular buffer it will never use, so
instead we replace this with an optional circular buffer. That optional
will be initialized on first use, so it doesn't add any complexity to
our state tracking. It does add some subtle complexity to the rest of
the grpc-web code, though, so we should consider increasing the priority
of dealing with grpc-web properly.

Modifications:

  • Make HTTP1ToGRPCServerCodec.responseTextBuffers optional, delay its
    initialization.

Results:

Small performance improvement on HTTP/2 server benchmarks, around 0.7%
per RPC.

Motivation:

Currently the HTTP1ToGRPCServerCodec constructs a CircularBuffer that it
only ever uses when doing grpc-web work. This is not the end of the
world, except that CircularBuffers require memory allocations: there is
no such thing as an empty CircularBuffer.

In general it's not a great idea to force the mainline grpc use-case to
pay for the cost of constructing a circular buffer it will never use, so
instead we replace this with an optional circular buffer. That optional
will be initialized on first use, so it doesn't add any complexity to
our state tracking. It does add some subtle complexity to the rest of
the grpc-web code, though, so we should consider increasing the priority
of dealing with grpc-web properly.

Modifications:

- Make HTTP1ToGRPCServerCodec.responseTextBuffers optional, delay its
  initialization.

Results:

Small performance improvement on HTTP/2 server benchmarks, around 0.7%
per RPC.
@Lukasa Lukasa requested a review from glbrntt August 7, 2020 12:28
Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Ace.

@glbrntt glbrntt merged commit da54baa into grpc:main Aug 7, 2020
@Lukasa Lukasa deleted the cb-avoid-unnecessary-circularbuffer branch August 7, 2020 13:08
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Aug 27, 2020
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