FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-111259: Optimize recursive wildcards in pathlib by serhiy-storchaka · Pull Request #111303 · python/cpython · GitHub

/ cpython Public

gh-111259: Optimize recursive wildcards in pathlib - #111303

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:pathlib-match-starstar-optimize
Oct 26, 2023
Merged

gh-111259: Optimize recursive wildcards in pathlib#111303
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:pathlib-match-starstar-optimize

Conversation

serhiy-storchaka commented Oct 25, 2023
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Regular expression pattern (?s:.) is much faster than [\s\S].

Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.

Copy link
Copy Markdown
Member

Is there a benchmark where this shows a clear improvement? I'm struggling to find one :/

I tried various simple benchmarks locally, such as

python -m timeit -n5 -r10 -s "from pathlib import Path" "list(Path('.').rglob('Lib/**/test_*.py'))"

I've no doubt that (?s:.) is much faster than [\s\S] in general, but here, I wonder if it makes a noticeable difference

AlexWaygood added performance Performance or resource usage topic-pathlib labels Oct 25, 2023

Copy link
Copy Markdown
Member Author

You can ask the OP. I guess that you can see some difference in match() for very long path.

Simple example (in debug build):

$ ./python -m timeit -s "from pathlib import Path; p = Path('a/'*1000)" "p.match('**/a')"
5000 loops, best of 5: 42.5 usec per loop

With this PR:

10000 loops, best of 5: 25.5 usec per loop

Copy link
Copy Markdown
Member

You can ask the OP. I guess that you can see some difference in match() for very long path.

Using a PGO-optimised build, I had to create an extremely long path for there to be a difference that wasn't just noise. But yeah, I can see a difference with this benchmark:

main:

>python -m timeit -n10 -r20 -s "from pathlib import Path; p = Path('a/'*1000000)" "p.match('**/a')"
Running PGUpdate|x64 interpreter...
10 loops, best of 20: 22.2 msec per loop

This PR:

10 loops, best of 20: 13 msec per loop

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, though you may want to wait for @barneygale's feedback, since he knows the code here much better than me :)

barneygale left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks fine to me, but perhaps worth noting that I'm intending to replace this code shortly - see #106703

That PR will only land in main, but this PR could be backported to 3.12 I think?

serhiy-storchaka merged commit 309efb3 into python:main Oct 26, 2023
serhiy-storchaka deleted the pathlib-match-starstar-optimize branch October 26, 2023 15:07
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…1303)

Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…1303)

Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL