Don't construct unnecessary buffers. #925
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
initialization.
Results:
Small performance improvement on HTTP/2 server benchmarks, around 0.7%
per RPC.