Title: Faster decode and find_max_char implementations. · Issue #120196 · python/cpython · GitHub
Open Graph Title: Faster decode and find_max_char implementations. · Issue #120196 · python/cpython
X Title: Faster decode and find_max_char implementations. · Issue #120196 · python/cpython
Description: Feature or enhancement Proposal: I have spotted a few inefficiencies in the stringlib implementations that hinder the compilers ability to optimize the code. These could be fixed. find_max_char, the 1-byte version. This unrolls checking ...
Open Graph Description: Feature or enhancement Proposal: I have spotted a few inefficiencies in the stringlib implementations that hinder the compilers ability to optimize the code. These could be fixed. find_max_char, th...
X Description: Feature or enhancement Proposal: I have spotted a few inefficiencies in the stringlib implementations that hinder the compilers ability to optimize the code. These could be fixed. find_max_char, th...
Opengraph URL: https://github.com/python/cpython/issues/120196
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Faster decode and find_max_char implementations.","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nI have spotted a few inefficiencies in the stringlib implementations that hinder the compilers ability to optimize the code. These could be fixed. \n\n- find_max_char, the 1-byte version. This unrolls checking 4 or 8-byte chunks. Alignment (which does not matter for x86-64 but may be important on other platforms) happens by checking one character at the time. This can be sped up by simply bitwise OR-ing all the characters together, and only check all the alginments with one check. Furthermore, the loop can be unrolled using 32-byte chunks. (4 size_t integers). By doing so, the compiler needs only very few extra instructions to do the bitwise or and can use 16-byte vectors. These are available on both x86-64 and ARM64 and the compiler will optimize easily. The less than 32 byte remainder can then be obtained by simply bitwise OR-ing these characters together and perform the check. \n- Find_max_char, the 2-byte and 4-byte version. These now work with unrolls of 4. For the 2-byte version this means an 8-byte load. Increasing the unroll to 8, this means 16-byte and 32-byte loads. The compiler can vectorize this. \n- Stringlib codecs.h utf8_decode on line 47 states, fast unrolled copy. These statements can be replaced by `memcpy(*_p, *_s, SIZEOF_SIZE_T); Using `*restrict` the compiler should understand that a read does not need to be performed twice, and memcpy using a fixed size is always optimized out. \n- ascii_decode: same as find_max_char. This can be optimized using larger chunks.\n\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-120212\n* gh-120497\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/rhpvorderman","@type":"Person","name":"rhpvorderman"},"datePublished":"2024-06-07T07:44:03Z","url":"https://github.com/python/cpython/issues/120196"}
| 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:cb6e6c2d-56b1-c4c9-8002-95719f42153a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8E6:1773CF:2CF3A8:3B5C94:6B02335B |
| html-safe-nonce | ece2b13a0967f7efcad5d5410e552cd79f21f675709be986254a06497d6f5a4b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEU2OjE3NzNDRjoyQ0YzQTg6M0I1Qzk0OjZCMDIzMzVCIiwidmlzaXRvcl9pZCI6IjQ0NDMyOTI4MTY1NDE2MjcyMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1956758ae9776e7f15d656d17d7eea00a798fa315ff60f7d4f59f822590bf633 |
| hovercard-subject-tag | issue:2339809802 |
| 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/120196/issue_layout |
| twitter:image | https://opengraph.githubassets.com/449c2a9a450137b72e4a73d8922d7ef31969484d22e83c9ac634a098ebd9f5c8/python/cpython/issues/120196 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/449c2a9a450137b72e4a73d8922d7ef31969484d22e83c9ac634a098ebd9f5c8/python/cpython/issues/120196 |
| og:image:alt | Feature or enhancement Proposal: I have spotted a few inefficiencies in the stringlib implementations that hinder the compilers ability to optimize the code. These could be fixed. find_max_char, th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rhpvorderman |
| 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