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 — [WIP] GH-102783: Speed up `pathlib.PurePath.__fspath__()` by returning raw path by barneygale · Pull Request #112397 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Nov 25, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Return an unnormalized path from pathlib.PurePath.__fspath__(). This is equivalent to a normalized path (because pathlib's normalization doesn't change the meaning of paths), but considerably cheaper to generate.

Draft PR because it depends on a fix for #65238.

  • Issue: Optimize pathlib.PurePath.__fspath__() #102783

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@barneygale
pythonGH-102783: Speed up pathlib.PurePath.__fspath__() by returnin…
2085494
…g raw path

Return an unnormalized path from `pathlib.PurePath.__fspath__()`. This is
equivalent to a normalized path (because pathlib's normalization doesn't
change the meaning of paths), but considerably cheaper to generate.
@barneygale barneygale added performance Performance or resource usage topic-pathlib labels Nov 25, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Nov 25, 2023
Optimize pathlib.PurePath.__fspath__() #102783
Closed
@barneygale

barneygale commented Nov 25, 2023

Copy link
Copy Markdown
Contributor Author

~3.5x faster for 0 or 1 initialiser arguments, ~2x faster for more:

$ ./python -m timeit -s "from pathlib import Path" "Path().__fspath__()"
200000 loops, best of 5:  1.9 usec per loop  # before
500000 loops, best of 5:  547 nsec per loop  # after
# --> 3.47x faster

$ ./python -m timeit -s "from pathlib import Path" "Path('foo').__fspath__()"
100000 loops, best of 5: 2.73 usec per loop  # before
500000 loops, best of 5:  719 nsec per loop  # after
# --> 3.80x faster

$ ./python -m timeit -s "from pathlib import Path" "Path('foo', 'bar').__fspath__()"
100000 loops, best of 5: 3.76 usec per loop  # before
200000 loops, best of 5: 1.82 usec per loop  # after
# --> 2.07x faster

$ ./python -m timeit -s "from pathlib import Path" "Path('foo', 'bar', 'baz').__fspath__()"
 50000 loops, best of 5: 4.12 usec per loop  # before
100000 loops, best of 5: 2.15 usec per loop  # after
# --> 1.92x faster
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale barneygale changed the title GH-102783: Speed up pathlib.PurePath.__fspath__() by returning raw path [WIP] GH-102783: Speed up pathlib.PurePath.__fspath__() by returning raw path Nov 25, 2023
barneygale added 2 commits December 4, 2023 18:08
@barneygale
Ignore empty segments.
0f4122a
@barneygale
Set slot values of empty paths up front.
8d94ffd
@barneygale

barneygale commented Dec 11, 2023

Copy link
Copy Markdown
Contributor Author

I'm going to implement this slightly differently, and it's reliant on a fix for #65238, so I'll close this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@barneygale barneygale closed this Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

performance Performance or resource usage topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@barneygale
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.