Fix performance of streaming long text#14941
Merged
krassowski merged 3 commits intoipython:mainfrom Aug 6, 2025
Merged
Conversation
krassowski
added a commit
that referenced
this pull request
Jul 19, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a performance issue when streaming long text output by changing the internal data structure from string concatenation to list accumulation. The change addresses issue #14937 where streaming large amounts of text was inefficient due to repeated string reallocation.
Key changes:
- Replaces string concatenation with list accumulation for stream data
- Updates type annotations to reflect the new data structure
- Adds a performance test to verify the fix
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_interactiveshell.py | Adds performance test for streaming operations |
| IPython/core/magics/basic.py | Updates notebook output handling to work with list-based stream data |
| IPython/core/interactiveshell.py | Changes stream data accumulation from string concatenation to list appending |
| IPython/core/history.py | Updates type annotation for bundle to support both string and list types |
Comments suppressed due to low confidence (1)
tests/test_interactiveshell.py:95
- The performance test only verifies that execution completes within 10 seconds but doesn't validate that the output is correct. Consider adding an assertion to verify that the expected output (numbers 0-249999) is actually produced.
assert duration < 10
Collaborator
|
This looks good! Thanks 🙌 |
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.
Fixes #14937
CC @Darshan808