Skip to content

Optimize joining of pathlib.PurePath() arguments. #104996

Closed

Description

@barneygale

In Python 3.12, when multiple arguments are given to PurePath(), the initialiser calls os.path.join() to join them. This is reasonably slow. For Python 3.13 we can make it faster by:

  1. Deferring joining of arguments until strictly needed
  2. (Maybe) re-implementing os.path.join(), as pathlib did before gh-94909: fix joining of absolute and relative Windows paths in pathlib  #95450.

Linked PRs

Activity

  1. added a commit that references this issue on May 26, 2023
  2. barneygale commented on May 26, 2023

    @barneygale
    ContributorAuthor

    The reason for (maybe) re-implementing os.path.join():

    Any implementation of path joining must keep a running record of the current drive, root and tail, and update them by calling splitroot() on each argument. The final drive, root and tail would be useful in pathlib to implement drive, root and _tail, but os.path.join() only makes available the joined path, which is a combination of the drive, root and tail. As a consequence, we need to call splitroot() all over again in _parse_path().

  3. added 6 commits that reference this issue on Jun 7, 2023
  4. added a commit that references this issue on Jul 19, 2023
  5. added a commit that references this issue on Oct 13, 2023
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

    3.13only security fixesperformancePerformance or resource usagetopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions