-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-112361: Speed up pathlib by removing some temporary objects. #112362
GH-112361: Speed up pathlib by removing some temporary objects. #112362
Conversation
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.)
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Thank you for the review Alex! |
…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()`
Construct only one new list object (using
list.copy()
) when creating a new path object with a modified tail. This slightly speeds upwith_name()
,with_suffix()
,_make_child_relpath()
(used in walking and globbing), andglob()
.