Title: Speed up UTF-8 validation in tokenizer and ASCII scanning in UTF-8 decoding · Issue #161145 · python/cpython · GitHub
Open Graph Title: Speed up UTF-8 validation in tokenizer and ASCII scanning in UTF-8 decoding · Issue #161145 · python/cpython
X Title: Speed up UTF-8 validation in tokenizer and ASCII scanning in UTF-8 decoding · Issue #161145 · python/cpython
Description: Feature or enhancement The tokenizer checks source is utf-8 with _PyTokenizer_ensure_utf8 one character at a time. Reuse _Py_find_first_nonascii to scan faster. That makes compile() for Lib/typing.py about 1% faster. Modify _Py_find_firs...
Open Graph Description: Feature or enhancement The tokenizer checks source is utf-8 with _PyTokenizer_ensure_utf8 one character at a time. Reuse _Py_find_first_nonascii to scan faster. That makes compile() for Lib/typing....
X Description: Feature or enhancement The tokenizer checks source is utf-8 with _PyTokenizer_ensure_utf8 one character at a time. Reuse _Py_find_first_nonascii to scan faster. That makes compile() for Lib/typing....
Opengraph URL: https://github.com/python/cpython/issues/161145
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Speed up UTF-8 validation in tokenizer and ASCII scanning in UTF-8 decoding","articleBody":"### Feature or enhancement\n\n - The tokenizer checks source is utf-8 with `_PyTokenizer_ensure_utf8` one character at a time. Reuse `_Py_find_first_nonascii` to scan faster. That makes `compile()` for `Lib/typing.py` about 1% faster.\n - Modify `_Py_find_first_nonascii` to test 64 bytes (32 on 32-bit platforms) of ASCII per branch. The code gets vectorized by some compilers and uses no intrinsics (https://godbolt.org/z/8bM83vx3a). `(b'a' * 4096).decode()` gets aout 1.5x faster.\n\n\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161146\n* gh-161147\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2026-11-01T23:08:10Z","url":"https://github.com/python/cpython/issues/161145"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b6e642ad-f9c6-ee87-f318-d7b92214e6f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FA0:24645:1900E85:20F0958:6B020F63 |
| html-safe-nonce | 2a4a24c230c3d3e55ae0fe65c3ed7c991459ea968c8b8ff59c2ef6243ac3303b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkEwOjI0NjQ1OjE5MDBFODU6MjBGMDk1ODo2QjAyMEY2MyIsInZpc2l0b3JfaWQiOiI0OTY5MjIzODc1NjA4MDU1NjUxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ae74936536f9b48aa81d3582bef3b5cadc8bb0f40ff11e1bfa785e772a8f82d5 |
| hovercard-subject-tag | issue:6153216697 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/161145/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c1661b470d03d0c97145dcb692020cfd398ecd4e720267f6b900eaf1a45d780d/python/cpython/issues/161145 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c1661b470d03d0c97145dcb692020cfd398ecd4e720267f6b900eaf1a45d780d/python/cpython/issues/161145 |
| og:image:alt | Feature or enhancement The tokenizer checks source is utf-8 with _PyTokenizer_ensure_utf8 one character at a time. Reuse _Py_find_first_nonascii to scan faster. That makes compile() for Lib/typing.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cmaloney |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width