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
commented
Nov 25, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…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.
|
~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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
|
I'm going to implement this slightly differently, and it's reliant on a fix for #65238, so I'll close this PR.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
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.
|