Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Comments
gh-117431: Improve performance of startswith and endswith#117782
gh-117431: Improve performance of startswith and endswith#117782eendebakpt wants to merge 17 commits intopython:mainfrom
Conversation
erlend-aasland left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Quick-and-dirty initial review.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Misc/NEWS.d/next/Core and Builtins/2024-04-11-21-17-23.gh-issue-117431.ZxdAFN.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
erlend-aasland commentedMay 21, 2024
Do you still see the"two-character fail head" slowdown? |
Misc/NEWS.d/next/Core and Builtins/2024-04-11-21-17-23.gh-issue-117431.ZxdAFN.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…e-117431.ZxdAFN.rstCo-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
eendebakpt commentedMay 21, 2024
Yes, and this is to be expected. For the two-character case we can either i) Check the first character and then the last (e.g. the second character). This is the current implementation in main The result is that main is faster for I have put some though into whether we could keep this PR more conservative (e.g. no cases with performance loss, but several cases with performance gain). The best I can create so far ismain...eendebakpt:tailmatch_v3. There are some more branches and the memcmp does a bit more work than required, but just like this PR it should improve matching the single-character and two-character case. |
Uh oh!
There was an error while loading.Please reload this page.
Improve performance of
startswithandendswithby eliminating double work intailmatch.Benchmark results:
Benchmark script
PyUnicode_READandmemcmpPyUnicode_READfrom happening twice.