Visitar URL original
GH-113373: Speed up pathlib parsing using `__init_subclass__()` by barneygale · Pull Request #113409 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260408194816/https://github.com/python/cpython/pull/113409
Skip to content
/ cpython Public

GH-113373: Speed up pathlib parsing using __init_subclass__()#113409

Closed
barneygale wants to merge 3 commits intopython:mainfrom
barneygale:purepathbase-init-subclass
Closed

GH-113373: Speed up pathlib parsing using __init_subclass__()#113409
barneygale wants to merge 3 commits intopython:mainfrom
barneygale:purepathbase-init-subclass

Conversation

@barneygale
Copy link
Copy Markdown
Contributor

@barneygale barneygale commented Dec 22, 2023 •

Set _sep, _altsep and _case_sensitive class attributes from _abc.PurePathBase.__init_subclass__(), which reduces the number of attribute accesses needed for several pathlib operations.

Set `_sep`, `_altsep` and `_case_sensitive` class attributes from
`_abc.PurePathBase.__init_subclass__()`, which reduces the number of
attribute accesses needed for several pathlib operations.
@barneygale
Copy link
Copy Markdown
Contributor Author

barneygale commented Dec 22, 2023 •

There's maybe a 3% speedup here:

$ ./python -m timeit -n 500000 -s "from pathlib import PurePath as P" "str(P('foo', 'bar'))"
500000 loops, best of 5: 4.31 usec per loop  # before
500000 loops, best of 5: 4.18 usec per loop  # after

A ~5% speedup here should be easier to reproduce:

$ ./python -m timeit -n 100000 -s "from pathlib import PurePath as P" "P('a/b') < P('c/d')"
100000 loops, best of 5: 9.68 usec per loop
100000 loops, best of 5: 9.16 usec per loop

@barneygale
Copy link
Copy Markdown
Contributor Author

Also fixes minor downstream backwards-compatibility problem: barneygale/pathlib-abc#9

@barneygale barneygale marked this pull request as draft December 29, 2023 00:16
@barneygale
Copy link
Copy Markdown
Contributor Author

Closing - it's not worth the weirdness.

@barneygale barneygale closed this Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage topic-pathlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant