Skip to content

perf: use _DummyListBuffer in test_reads.py to avoid GIL contention#16860

Open
zhixiangli wants to merge 2 commits intogoogleapis:mainfrom
zhixiangli:perf-reads-benchmark
Open

perf: use _DummyListBuffer in test_reads.py to avoid GIL contention#16860
zhixiangli wants to merge 2 commits intogoogleapis:mainfrom
zhixiangli:perf-reads-benchmark

Conversation

@zhixiangli
Copy link
Copy Markdown
Contributor

This PR replaces io.BytesIO with a custom _DummyListBuffer in test_reads.py.

During profiling, io.BytesIO.write() holds the GIL while copying data. This introduces significant noise and bottlenecks in performance tests with high concurrency or large data transfers.

This change avoids GIL contention and reduces noise when profiling the code (specifically noted by the user as causing noise when profiling the format code).

@zhixiangli zhixiangli requested a review from a team as a code owner April 29, 2026 01:21
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a _DummyListBuffer class to replace io.BytesIO in performance tests, which helps avoid GIL contention during profiling. Feedback includes a suggestion to make the write method compliant with standard Python io interfaces by returning the number of bytes written and a recommendation to optimize memory usage by removing chunk storage if the data content is not being verified.

Also fixed a pre-existing lint error (unused import io.BytesIO).
@zhixiangli zhixiangli enabled auto-merge (squash) April 29, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant