fix(google-crc32c): release GIL for large buffers in crc32c operations#16975
Open
zhixiangli wants to merge 1 commit intogoogleapis:mainfrom
Open
fix(google-crc32c): release GIL for large buffers in crc32c operations#16975zhixiangli wants to merge 1 commit intogoogleapis:mainfrom
zhixiangli wants to merge 1 commit intogoogleapis:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to release the Python Global Interpreter Lock (GIL) during CRC32C calculations for large, immutable buffers (>= 1MB) to improve performance in multi-threaded applications. This is achieved by adding a helper function _should_release_gil and wrapping the core calculation calls with PyEval_SaveThread and PyEval_RestoreThread. The review feedback points out that the inclusion of the <stdlib.h> header is unnecessary and should be removed to maintain code cleanliness.
dc41f67 to
27155d3
Compare
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.
Release the Global Interpreter Lock (GIL) in
_crc32c_extendand_crc32c_valuewhen processing large, immutable byte buffers (>= 1MB). This allows other Python threads to run concurrently during expensive crc32c calculations on large chunks of data.Fixes #16923 🦕
Unit Tests
Perf Tests
Methodology
Created an independent benchmark script (shown below) that measures the time taken for
crc32c.value()on different buffer sizes (10KB to 10MB) with 1 thread and 4 threads.Results
Conclusion
Code