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 `pathlib.Path.iterdir()` by using `os.scandir()` · Issue #117727 · python/cpython

Speed up pathlib.Path.iterdir() by using os.scandir() #117727

New issue
Copy link
New issue
Copy link
Closed
Closed
Speed up pathlib.Path.iterdir() by using os.scandir()#117727
Copy link
Labels
performancePerformance or resource usagePerformance or resource usagetopic-pathlib

Description

@barneygale
barneygale
opened on Apr 10, 2024
Issue body actions

We should be able to call os.scandir() from pathlib.Path.iterdir() and construct results based on the os.DirEntry.path string.

Currently we call os.listdir() and _make_child_relpath(), which returns a fully parsed/normalized string; particularly, it sets _str, _drv, _root and _tail_cached.

It's probably not worth the expense of setting _drv, _root and _tail_cached - they're only useful when paths are subsequently deconstructed with PurePath methods, which isn't particularly common. It is worth setting _str, and happily os.DirEntry.path provides a string that's very nearly normalized to pathlib's standards.

Also discussed here: https://discuss.python.org/t/is-there-a-pathlib-equivalent-of-os-scandir/46626/21

Linked PRs

  • GH-117727: Speed up pathlib.Path.iterdir() by using os.scandir() #117728

Activity

  1. barneygale
    added
    performancePerformance or resource usagePerformance or resource usage
    topic-pathlib
    on Apr 10, 2024
  2. barneygale
    added 2 commits that reference this issue on Apr 10, 2024

    pythonGH-117727: Speed up `pathlib.Path.iterdir()` by using `os.scand…

    84534f9

    GH-117727: Speed up `pathlib.Path.iterdir()` by using `os.scandir()` (#…

    30f0643
  3. barneygale
    closed this as completedon Apr 12, 2024
  4. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythonGH-117727: Speed up `pathlib.Path.iterdir()` by using `os.scand…

    cd462e6
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 usagetopic-pathlib

    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.