Repository navigation
Fix quadratic time reading large stdio responses - #3700
guptaishaan wants to merge 1 commit into
Conversation
stdout_reader rebuilt "buffer + chunk" for every chunk, so a single large JSON line was re-copied once per chunk read. Receiving N bytes cost O(N^2). Keep the pieces of the unfinished line in a list and join them once when a chunk contains a newline.
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3699. If a maintainer assigns you to #3699, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3699
Motivation and Context
stdio_clienttook quadratic time to receive a large response.stdout_readerdid(buffer + chunk).split("\n")for every chunk, so one big JSON line was re-copied once per chunk.Now chunks without a newline are collected in a list and joined once when the line ends. Thanks to the reporter of #3699 for the diagnosis and the proposed change.
Real client and server over pipes (the issue's script), 16 MB reply: 6.29 s before, 0.19 s after. 32 MB: 22.86 s before, 0.39 s after.
How Has This Been Tested?
tests/client/test_stdio.pyfeeds an 8 MB line in 1 KB chunks to the fake process. It times out (5 s) without the fix and passes in about 0.08 s with it.tests/client/test_stdio.pyandtests/interaction/transports/test_stdio.pypass (38 tests).ruff checkandruff format --checkare clean.Breaking Changes
None.
Types of changes
Checklist
help wanted, or I'm a maintainer)Additional context
AI disclosure: this change was written and tested by an automated Claude agent run, not by hand.