Repository navigation
Split streamed lines - #43
Open
vincent0426 wants to merge 1 commit into
Open
vincent0426 wants to merge 1 commit into
vincent0426 wants to merge 1 commit into
Conversation
response_lines re-split the whole pending buffer on every chunk, so a long line arriving in many chunks took quadratic time: an 8 MB line in 16 KB chunks took about 17s to split, and about 26s through stream_logs on a live sandbox. Lines without a line ending are common in process output, such as progress bars, minified JSON and base64. The buffer is now split only when a chunk contains \n, the only way a line can end, so an unfinished line is not rescanned.
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues with the streamed-log processing optimization.
No open issues 🎉
What changed in this PR
Improves streamed log processing by avoiding repeated scans of incomplete lines in the synchronous and asynchronous response readers.
Changes:
- Splits the accumulated buffer only when newly decoded text contains a newline.
- Adds a regression case for a long line spanning many chunks, with
\r\nsplit across chunks.
| File | Description |
|---|---|
tests/sandbox/test_common.py |
Adds coverage for long chunked lines and split CRLF endings. |
baseten/sandbox/_common.py |
Avoids unnecessary buffer splitting in both response readers. |
Review effort: Balanced
This branch has not been deployed
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.
🚀 What
stream_logsgot slower the longer a line was: each chunk rescanned the whole line so far, so one 8 MB line took ~26s on a live sandbox.💻 How
response_linesresplit the whole buffer on every chunk. It now checks only the new chunk for\nand splits the buffer only when one is found.🔬 Testing
Splitting one long line in 16 KB chunks:
All existing tests pass;
poe lintandpoe typecheckare clean.also tried splitting only the new chunk instead of the whole buffer. It saves ~60ms on an 8 MB line (0.068s → 0.006s) but needs more code to handle
\r\nsplit across chunks, so I kept the simpler change.