[Python] Remove GIL from ReceiveMessageOperation.un_c method#41812
Closed
googlyrahman wants to merge 1 commit into
Closed
[Python] Remove GIL from ReceiveMessageOperation.un_c method#41812googlyrahman wants to merge 1 commit into
googlyrahman wants to merge 1 commit into
Conversation
|
|
Member
|
/gemini review |
Contributor
There was a problem hiding this comment.
Code Review
This pull request aims to reduce GIL contention when receiving messages by changing how byte buffers are constructed. The approach of collecting byte chunks in a list and then using b"".join() is a good improvement over repeated concatenation to a bytearray.
I've provided one suggestion for a more significant optimization. By leveraging grpc_byte_buffer_reader_readall from the C-core library, you can avoid the overhead of the Python-level loop and object creation entirely, leading to better performance. This requires a small change to expose the function to Cython, which I've detailed in my comment.
6ad31ae to
45ecf70
Compare
sergiitk
approved these changes
Mar 18, 2026
asheshvidyut
pushed a commit
to asheshvidyut/grpc
that referenced
this pull request
Mar 26, 2026
) Remove one of the GIL contention from the grpc python wrapper. The python [releases the GIL](python/cpython#17757) while doing b"".join. This was one of the major GIL contention in the python wrapper. Fixing this significantly reduces the GIL contention. Closes grpc#41812 COPYBARA_INTEGRATE_REVIEW=grpc#41812 from googlyrahman:samplefix df4796a PiperOrigin-RevId: 888241985
asheshvidyut
pushed a commit
to asheshvidyut/grpc
that referenced
this pull request
Apr 8, 2026
) Remove one of the GIL contention from the grpc python wrapper. The python [releases the GIL](python/cpython#17757) while doing b"".join. This was one of the major GIL contention in the python wrapper. Fixing this significantly reduces the GIL contention. Closes grpc#41812 COPYBARA_INTEGRATE_REVIEW=grpc#41812 from googlyrahman:samplefix df4796a PiperOrigin-RevId: 888241985
asheshvidyut
pushed a commit
to a-detiste/grpc
that referenced
this pull request
Jun 10, 2026
) Remove one of the GIL contention from the grpc python wrapper. The python [releases the GIL](python/cpython#17757) while doing b"".join. This was one of the major GIL contention in the python wrapper. Fixing this significantly reduces the GIL contention. Closes grpc#41812 COPYBARA_INTEGRATE_REVIEW=grpc#41812 from googlyrahman:samplefix df4796a PiperOrigin-RevId: 888241985
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remove one of the GIL contention from the grpc python wrapper.
The python releases the GIL while doing b"".join. This was one of the major GIL contention in the python wrapper.
Fixing this significantly reduces the GIL contention.