Skip to content

Fix performance of streaming long text#14941

Merged
krassowski merged 3 commits intoipython:mainfrom
krassowski:fix-printing-speed
Aug 6, 2025
Merged

Fix performance of streaming long text#14941
krassowski merged 3 commits intoipython:mainfrom
krassowski:fix-printing-speed

Conversation

@krassowski
Copy link
Member

@krassowski krassowski commented Jul 19, 2025

Fixes #14937

  • adds failing test
  • fixes the issue by using list of lines to accumulate stream instead or re-allocating a long string each time

CC @Darshan808

krassowski added a commit that referenced this pull request Jul 19, 2025
@krassowski krassowski marked this pull request as ready for review July 19, 2025 09:33
@krassowski krassowski added this to the 9.5 milestone Jul 19, 2025
@krassowski krassowski requested a review from Copilot August 5, 2025 16:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@Darshan808
Copy link
Collaborator

This looks good! Thanks 🙌

@krassowski krassowski merged commit eeb177f into ipython:main Aug 6, 2025
18 checks passed
@krassowski krassowski deleted the fix-printing-speed branch August 6, 2025 10:55
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.

Printing many lines of output is ~50x slower in ipython v9.1.0 and above compared to v9.0.2 and below

2 participants