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 import rlcompleter by deferring inspect and re · Issue #156363 · python/cpython

Speed up import rlcompleter by deferring inspect and re #156363

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Speed up import rlcompleter by deferring inspect and re#156363
Copy link
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

@maxday
maxday
opened on Aug 25, 2026
Issue body actions

rlcompleter imports inspect and re at module scope, but neither is needed to import the module or to construct a Completer. Each is used in exactly one completion method:

  • inspect: only in Completer._callable_postfix
  • re: only in Completer.attr_matches

inspect in particular is a heavy import: it transitively pulls in dis, tokenize, and more. Because rlcompleter is imported during interactive startup (to set up tab completion via readline), this import cost is paid on every interactive session and every import rlcompleter, even though the completion methods may never run.

Linked PRs

  • gh-156363: Speed up import of rlcompleter by deferring inspect and re #156364

Activity

  1. maxday commented on Aug 25, 2026

    @maxday
    maxday
    on Aug 25, 2026
    ContributorAuthor
    More actions

    I'm working on this :)

  2. maxday
    added 2 commits that reference this issue on Aug 25, 2026

    pythongh-156363: Speed up import of rlcompleter by deferring inspect …

    aa2ebff

    pythongh-156363: Speed up import of rlcompleter by deferring inspect …

    fadfaf9
  3. aisk
    added
    performancePerformance or resource usagePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Aug 25, 2026
  4. hugovk
    added a parent issue on Aug 25, 2026
    • Improve import time of various stdlib modules #154675
  5. maxday
    added 2 commits that reference this issue on Aug 25, 2026

    pythongh-156363: Use PEP 810 lazy imports for inspect and re in rlcom…

    0ba9e10

    pythongh-156363: Use PEP 810 lazy imports for inspect and re in rlcom…

    a79e157
  6. StanFromIreland
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 26, 2026
  7. aisk commented on Aug 26, 2026

    @aisk
    aisk
    on Aug 26, 2026
    Member
    More actions

    One thing to notice, on the interactive startup path these two modules get imported a moment later anyway, since _pyrepl.readline is imported right after rlcompleter and pulls them both in:

    $ ./python -c "import sys, _pyrepl.readline; print('re' in sys.modules, 'inspect' in sys.modules)"
    True True

    So the gain doesn't really materialize for the interactive interpreter. It may still help people who use this module on its own, though.

  8. maxday commented on Aug 28, 2026

    @maxday
    maxday
    on Aug 28, 2026
    ContributorAuthor
    More actions

    You're right @aisk, on the default PyREPL path _pyrepl.readline pulls in both re (directly) and inspect (via dataclasses(slots=True) in _pyrepl/utils.py), so the deferral is neutral there.

    It does still help in two cases: PYTHON_BASIC_REPL=1, where site.py skips the _pyrepl.readline import entirely, and standalone use of rlcompleter (e.g. readline.set_completer(rlcompleter.Completer(ns).complete)), where importing the module drops from ~15 ms to ~1.6 ms and avoids ~35 transitive modules.

    It also helps people who use this module on its own indeed.

    Since it's neutral on the common path and a win on the others and in line with the ongoing startup-time / PEP 810 work, I think it's still worth doing, let me know!

  9. seth-957
    added a commit that references this issue on Sep 6, 2026

    pythongh-156363, pythongh-156491: Speed up rlcompleter import and opt…

    c8cf419
  10. StanFromIreland
    closed this as not plannedon Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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.