-
Notifications
You must be signed in to change notification settings - Fork 28
Optimize gRPC request processing: fast negotiation path and reduced per-request allocations #739
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
Open
He-Pin
wants to merge
16
commits into
apache:main
Choose a base branch
from
He-Pin:optimize/fast-negotiation-uri-match
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c8381c3
Optimize gRPC request processing: fast negotiation path and URI strin…
He-Pin 8d92d6b
Prefer Identity codec over Gzip for response encoding
He-Pin 49faba6
Prefer Identity codec for gRPC response encoding to eliminate Gzip ov…
He-Pin 09de7e3
Pre-create unary method lambdas to avoid per-request allocation
He-Pin 5a1855c
refactor: optimize native identity strict gRPC decoding
He-Pin c3634af
Reduce per-request allocations on unary gRPC hot path
He-Pin dcd2ab3
Add offset-aware protobuf deserialization to avoid ByteString.slice a…
He-Pin bcf98c1
Apply offset-aware deserialization to Java DSL unmarshal strict path
He-Pin dc04304
Optimize methodName to use Uri.Path structure matching instead of toS…
He-Pin 8f0a44c
Eliminate Option.map lambda allocation in negotiated method
He-Pin 4c95598
fix: add empty data check in ProtobufFrameSerializer fast path for ha…
He-Pin 75444a2
fix: use value equality for gRPC content-type string comparison
He-Pin bce5b4a
refactor: JIT/GC optimizations on unary hot path
He-Pin 4fa56d2
chore: apply scalafmt
He-Pin fba6d25
fix: respect grpc-accept-encoding in negotiate fast path and address …
He-Pin 8729a6c
fix: address review findings — frame validation, test assertion, and …
He-Pin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,32 @@ object GrpcProtocolNative extends AbstractGrpcProtocol("grpc") { | |
| AbstractGrpcProtocol.writer(this, codec, encodeFrame(codec, _), encodeDataToResponse(codec)) | ||
|
|
||
| override protected def reader(codec: Codec): GrpcProtocolReader = | ||
| AbstractGrpcProtocol.reader(codec, decodeFrame) | ||
| if (codec eq Identity) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this identity codec change, can it be done in the gzip PR instead? |
||
| AbstractGrpcProtocol.reader(codec, decodeFrame).copy(decodeSingleFrame = decodeIdentitySingleFrame) | ||
| else AbstractGrpcProtocol.reader(codec, decodeFrame) | ||
|
|
||
| @inline | ||
| private def decodeFrame(@nowarn("msg=is never used") frameType: Int, data: ByteString) = DataFrame(data) | ||
|
|
||
| private def decodeIdentitySingleFrame(frame: ByteString): ByteString = { | ||
| if (frame.length < AbstractGrpcProtocol.FrameHeaderSize) throw new MissingParameterException | ||
|
|
||
| val frameType = frame(0) | ||
| val length = frame.readIntBE(1) | ||
| val available = frame.length - AbstractGrpcProtocol.FrameHeaderSize | ||
| if (length > available) throw new MissingParameterException | ||
| if (length < 0) throw new IllegalStateException(s"Invalid frame length: $length") | ||
| if (length < available) | ||
| throw new IllegalStateException("Unexpected trailing data") | ||
| if ((frameType & 0x80) != 0) throw new IllegalStateException("Cannot read unknown frame") | ||
|
|
||
| if ((frameType & 1) != 0) | ||
| throw new io.grpc.StatusException( | ||
| io.grpc.Status.INTERNAL.withDescription( | ||
| "Compressed-Flag bit is set, but a compression encoding is not specified")) | ||
| frame.drop(AbstractGrpcProtocol.FrameHeaderSize) | ||
| } | ||
|
|
||
| @inline | ||
| private def encodeFrame(codec: Codec, frame: Frame): ChunkStreamPart = | ||
| frame match { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this gzip change be handled only in the new separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will rebate, I think I will continues it this weekends