Skip to content

Speed up pathlib by removing a few temporary objects #112361

Closed
@barneygale

Description

@barneygale

A handful of pathlib methods that create paths with modified names, or additional segments, use list objects that are quickly thrown away. We can speed these methods up by only creating new lists where strictly necessary.

Specifically:

  • with_name() (performance of self._tail[:-1] + [name] is cursed)
  • with_suffix()
  • _make_child_relpath() (used in glob() and walk())
  • glob() (when parsing the pattern)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions