René's URL Explorer Experiment


Title: `re`: no ASCII fast path for `\w` in Unicode mode, unlike `\s` · Issue #159251 · python/cpython · GitHub

Open Graph Title: `re`: no ASCII fast path for `\w` in Unicode mode, unlike `\s` · Issue #159251 · python/cpython

X Title: `re`: no ASCII fast path for `\w` in Unicode mode, unlike `\s` · Issue #159251 · python/cpython

Description: Feature or enhancement Use the existing ASCII table to speed up word matching for ASCII characters, while keeping Unicode by default. For example: >>> import re >>> re.findall(r"\w+", "hello café 123") ['hello', 'café', '123'] Most chara...

Open Graph Description: Feature or enhancement Use the existing ASCII table to speed up word matching for ASCII characters, while keeping Unicode by default. For example: >>> import re >>> re.findall(r"\w+", "hello café 1...

X Description: Feature or enhancement Use the existing ASCII table to speed up word matching for ASCII characters, while keeping Unicode by default. For example: >>> import re >>> re.findall(r&q...

Opengraph URL: https://github.com/python/cpython/issues/159251

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`re`: no ASCII fast path for `\\w` in Unicode mode, unlike `\\s`","articleBody":"### Feature or enhancement\n\nUse the existing ASCII table to speed up word matching for ASCII characters, while keeping Unicode by default.\n\nFor example:\n\n```python\n>>> import re\n>>> re.findall(r\"\\w+\", \"hello café 123\")\n['hello', 'café', '123']\n```\n\nMost characters in this example are ASCII, but the `re` still uses Unicode classification for each character that `\\w` examines.\n\n## Idea\n\nThe idea is for chars less than 128, use `SRE_IS_WORD()`. For the rest, keep the existing Unicode predicate:\n\n```c\n#define SRE_UNI_IS_WORD(ch)\\\n    ((ch) \u003c 128 ? SRE_IS_WORD(ch) : (SRE_UNI_IS_ALNUM(ch) || (ch) == '_'))\n```\n\nThe same predicate is used by `\\W`, `\\b` and `\\B` so it'd speed them up, too.\n\nWe're doing it for `\\s`:\n\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Include/cpython/unicodeobject.h#L753-L758\n\n## Microbenchmark\n\n| Benchmark | main | patched |\n|---|---:|---:|\n| `\\w+` findall, ASCII prose | 295 us | 235 us (1.25x faster) |\n| `\\w+\\|[^\\w\\s]+` (NLTK WordPunct), ASCII prose | 417 us | 327 us (1.28x faster) |\n| `\\W+` findall, ASCII prose | 321 us | 276 us (1.16x faster) |\n| `\\b\\w` findall, ASCII prose | 347 us | 223 us (1.55x faster) |\n| `\\w+` findall, ASCII punctuation only | 132 us | 81.8 us (1.61x faster) |\n| `\\w+` findall, Latin-1 prose | 326 us | 270 us (1.21x faster) |\n| `\\w+` findall, CJK text | 71.8 us | 77.4 us (1.08x slower) |\n| `\\w+` findall, mixed scripts | 206 us | 172 us (1.20x faster) |\n| `\\w+` findall with `re.ASCII` (control) | 229 us | not significant |\n| `\\d+` findall, ASCII prose (control) | 154 us | 165 us (1.07x slower) |\n\nLinux (AMD EPYC 4484PX, Ubuntu 24.04, gcc 13), PGO+LTO builds of `main` at 9028df36bb9e\n\n`perf stat -r 5` on the same machine:\n\n| Case | main instructions | patched instructions | main cycles | patched cycles |\n|---|---:|---:|---:|---:|\n| `\\w+` ASCII prose | 14.85G | 12.14G (-18%) | 3.20G | 2.61G (-18%) |\n| NLTK WordPunct, ASCII prose | 15.64G | 12.84G (-18%) | 3.32G | 2.68G (-19%) |\n| `\\w+` CJK text | 13.63G | 13.50G (-1%) | 2.97G | 3.27G (+10%) |\n| `\\w+` with `re.ASCII` (control) | 12.08G | 12.09G (0%) | 2.57G | 2.55G (-1%) |\n| `\\d+` ASCII prose (control) | 14.85G | 14.85G (0%) | 3.03G | 3.09G (+2%) |\n\nSo the `\\d+` is likely just noise between PGO+LTO builds, but 100% CJK seems to be real cost. Are we ok with it? \n\n\u003cdetails>\n\u003csummary>pyperf microbenchmark\u003c/summary>\n\n```python\nimport re\n\nimport pyperf\n\nascii_text = (\"The quick brown fox jumps over the lazy dog, said Alice; \"\n              \"it was 42 degrees outside and the kettle_was on. \") * 200\nlatin_text = (\"Zażółć gęślą jaźń, señor; la niña está aquí: café, \"\n              \"naïve, crème brûlée. \") * 300\ncjk_text = \"漢字仮名交じり文で書かれた文章です。これはテストの文章です。\" * 300\nmixed_text = (ascii_text[:2000] + latin_text[:1000] + cjk_text[:500]) * 4\npunct_text = \"!!! ??? ... --- *** ((( ))) ;;; ::: ,,, \" * 300\n\nword_run = re.compile(r\"\\w+\")\nnltk_wordpunct = re.compile(r\"\\w+|[^\\w\\s]+\")\nnonword_split = re.compile(r\"\\W+\")\nboundary = re.compile(r\"\\b\\w\")\nascii_flag = re.compile(r\"\\w+\", re.ASCII)\ndigit_run = re.compile(r\"\\d+\")\n\n\ndef findall(pattern, text):\n    return pattern.findall(text)\n\n\nrunner = pyperf.Runner()\nrunner.bench_func(r\"\\w+ findall, ASCII prose\", findall, word_run, ascii_text)\nrunner.bench_func(r\"\\w+|[^\\w\\s]+ (NLTK WordPunct), ASCII prose\", findall, nltk_wordpunct, ascii_text)\nrunner.bench_func(r\"\\W+ findall, ASCII prose\", findall, nonword_split, ascii_text)\nrunner.bench_func(r\"\\b\\w findall, ASCII prose\", findall, boundary, ascii_text)\nrunner.bench_func(r\"\\w+ findall, ASCII punctuation only\", findall, word_run, punct_text)\nrunner.bench_func(r\"\\w+ findall, Latin-1 prose\", findall, word_run, latin_text)\nrunner.bench_func(r\"\\w+ findall, CJK text\", findall, word_run, cjk_text)\nrunner.bench_func(r\"\\w+ findall, mixed scripts\", findall, word_run, mixed_text)\nrunner.bench_func(r\"\\w+ findall with re.ASCII (control)\", findall, ascii_flag, ascii_text)\nrunner.bench_func(r\"\\d+ findall, ASCII prose (control)\", findall, digit_run, ascii_text)\n```\n\n\u003c/details>\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159252\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/maurycy","@type":"Person","name":"maurycy"},"datePublished":"2026-10-12T19:19:54Z","url":"https://github.com/python/cpython/issues/159251"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:84078a7b-bd51-e15e-c4db-2abc0b80d062
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8E36:26ECEB:3D8C64D:4E37239:6B01FA1E
html-safe-nonce4b448028e0cc830c9c7d70e77249269679ed6d45b499045510287115c9db0e34
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTM2OjI2RUNFQjozRDhDNjREOjRFMzcyMzk6NkIwMUZBMUUiLCJ2aXNpdG9yX2lkIjoiNjkwNjQ0OTAzMTcxOTk0MjY4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace521238872f52042eccfa065ee798a139f3e4c7a55ec9182ce211d5c6560e9d8
hovercard-subject-tagissue:5819205320
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/159251/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cc35bbd9a58bc3d10851c6c9261084646565db994d71601c08ba4ba09b68929b/python/cpython/issues/159251
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cc35bbd9a58bc3d10851c6c9261084646565db994d71601c08ba4ba09b68929b/python/cpython/issues/159251
og:image:altFeature or enhancement Use the existing ASCII table to speed up word matching for ASCII characters, while keeping Unicode by default. For example: >>> import re >>> re.findall(r"\w+", "hello café 1...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemaurycy
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/159251#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159251
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159251
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/159251
Reloadhttps://github.com/python/cpython/issues/159251
Reloadhttps://github.com/python/cpython/issues/159251
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159251
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159251
re: no ASCII fast path for \w in Unicode mode, unlike \shttps://github.com/python/cpython/issues/159251#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
topic-regexhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-regex%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 12, 2026https://github.com/python/cpython/issues/159251#issue-5819205320
cpython/Include/cpython/unicodeobject.hhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Include/cpython/unicodeobject.h#L753-L758
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
gh-159251: re: Add an ASCII fast path to \w in Unicode mode #159252https://github.com/python/cpython/pull/159252
maurycyhttps://github.com/maurycy
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Oct 12, 2026https://github.com/python/cpython/issues/159251#event-33074670420
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 12, 2026https://github.com/python/cpython/issues/159251#issuecomment-6131543751
@serhiy-storchakahttps://github.com/serhiy-storchaka
https://github.com/terryjreedy
terryjreedyhttps://github.com/terryjreedy
on Oct 12, 2026https://github.com/python/cpython/issues/159251#issuecomment-6134382215
picnixzhttps://github.com/picnixz
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-regexhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-regex%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Oct 13, 2026https://github.com/python/cpython/issues/159251#event-33092515199
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Oct 13, 2026https://github.com/python/cpython/issues/159251#issuecomment-6135930208
@serhiy-storchakahttps://github.com/serhiy-storchaka
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 13, 2026https://github.com/python/cpython/issues/159251#issuecomment-6140434277
@terryjreedyhttps://github.com/terryjreedy
#159252https://github.com/python/cpython/pull/159252
6c5f44fhttps://github.com/python/cpython/commit/6c5f44f8a16a657d3c82d4beb2eee0795a81ad77
cpython/Lib/test/test_capi/test_unicode.pyhttps://github.com/python/cpython/blob/48ddda1987a17fa96d74409b9eccb7379f61816f/Lib/test/test_capi/test_unicode.py#L2600-L2614
48ddda1https://github.com/python/cpython/commit/48ddda1987a17fa96d74409b9eccb7379f61816f
maurycyhttps://github.com/maurycy
on Oct 13, 2026https://github.com/python/cpython/issues/159251#event-33112602769
https://github.com/python/cpython/issues/159251#issuecomment-6140434277https://github.com/maurycy/cpython/commit/6c5f44f8a16a657d3c82d4beb2eee0795a81ad77
6c5f44fhttps://github.com/maurycy/cpython/commit/6c5f44f8a16a657d3c82d4beb2eee0795a81ad77
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 13, 2026https://github.com/python/cpython/issues/159251#issuecomment-6146892251
https://github.com/terryjreedy
terryjreedyhttps://github.com/terryjreedy
on Oct 13, 2026https://github.com/python/cpython/issues/159251#issuecomment-6156030389
picnixzhttps://github.com/picnixz
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Oct 13, 2026https://github.com/python/cpython/issues/159251#event-33175493165
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159251#event-33592163620
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159251
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159251#event-33592179846
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/159251
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/159251
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
topic-regexhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-regex%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.