Skip to content

Fix performance of streaming long text #14941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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 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
Contributor

This looks good! Thanks 🙌

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy