Uh oh!
There was an error while loading. Please reload this page.
gh-117431: Improve performance of startswith and endswith - #117782
gh-117431: Improve performance of startswith and endswith#117782eendebakpt wants to merge 17 commits into
Conversation
erlend-aasland
left a comment
There was a problem hiding this comment.
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>
Uh oh!
There was an error while loading. Please reload this page.
erlend-aasland
commented
May 21, 2024
Do you still see the "two-character fail head" slowdown? |
Uh oh!
There was an error while loading. Please reload this page.
…e-117431.ZxdAFN.rst Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
eendebakpt
commented
May 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 is main...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. |
This PR is stale because it has been open for 30 days with no activity. |
Improve performance of
startswithandendswithby eliminating double work intailmatch.Benchmark results:
Benchmark script
PyUnicode_READandmemcmpPyUnicode_READfrom happening twice.