| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Construct only one new list object (using `list.copy()`) when creating a new path object with a modified tail. This slightly speeds up `with_name()`, `with_suffix()`, `_make_child_relpath()` (used in walking and globbing), and `glob()`.
|
Timings: $ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo')" "p.with_name('bar')"
1000000 loops, best of 5: 1.44 usec per loop # before
1000000 loops, best of 5: 1.31 usec per loop # after
$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo.txt')" "p.with_suffix('.zip')"
1000000 loops, best of 5: 2.02 usec per loop # before
1000000 loops, best of 5: 1.83 usec per loop # after
$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo.txt')" "p.with_suffix('')"
1000000 loops, best of 5: 1.88 usec per loop # before
1000000 loops, best of 5: 1.68 usec per loop # after
$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo')" "p._make_child_relpath('bar')"
1000000 loops, best of 5: 1.14 usec per loop # before
1000000 loops, best of 5: 1.11 usec per loop # after
|
Sorry, something went wrong.
There was a problem hiding this comment.
Overall this looks really nice -- great work! I can reproduce the big speedups from the first three benchmarks in #112362 (comment).
I can't repro the reported speedup for _make_child_relpath, though (the fourth benchmark from #112362 (comment)) -- if anything, it looks like this PR makes it slightly slower for me locally? (I'm on Windows with a fresh PGO-optimised build from main.)
Sorry, something went wrong.
Hm. With a fresh PGO rebuild on Linux I still see an improvement, but it's really marginal - only 2% faster. I'll take the change out of the PR. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks great, thanks!
Sorry, something went wrong.
|
Thank you for the review Alex! |
Sorry, something went wrong.
…python#112362) Construct only one new list object (using `list.copy()`) when creating a new path object with a modified tail. This slightly speeds up `with_name()` and `with_suffix()`
…python#112362) Construct only one new list object (using `list.copy()`) when creating a new path object with a modified tail. This slightly speeds up `with_name()` and `with_suffix()`
| Back | FazBrowse Home | New Git URL |
Construct only one new list object (using list.copy()) when creating a new path object with a modified tail. This slightly speeds up with_name(), with_suffix(), _make_child_relpath() (used in walking and globbing), and glob().