GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Speed up `pprint` on deeply nested containers · Issue #161114 · python/cpython

Speed up pprint on deeply nested containers #161114

New issue
Copy link
New issue
Copy link
Open
#161115
Open
Speed up pprint on deeply nested containers#161114
#161115
Copy link
Assignees
gpshead
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@gpshead
gpshead
opened on Nov 1, 2026
Issue body actions

Feature or enhancement

Proposal:

pprint.pformat() decides whether a container fits on the current line by building its complete one-line repr, and when it doesn't, it repeats that for each child. For deeply nested data the innermost items are therefore formatted once per enclosing level, so the time grows with size times depth.

import json, pprint, time
flat = json.loads("[" + ",".join(["1"] * 20000) + "]")
deep = json.loads("[" * 300 + ",".join(["1"] * 20000) + "]" * 300)
for o in flat, deep:
    t = time.perf_counter(); pprint.pformat(o); print(time.perf_counter() - t)

The nested version takes about 40x longer than the flat one (0.07 s vs 2.6 s on a release build). The fit check can stop once the line is full, which makes it cost at most the line width per level; output stays the same.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-161114: Speed up pprint on deeply nested containers #161115

Activity

  1. gpshead
    self-assigned this
    on Nov 1, 2026
  2. gpshead
    added
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gpshead
    gpshead

Labels

performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.