-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-117431: Improve performance of startswith and endswith #117782
base: main
Are you sure you want to change the base?
Conversation
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.
Co-authored-by: Erlend E. Aasland <[email protected]>
Misc/NEWS.d/next/Core and Builtins/2024-04-11-21-17-23.gh-issue-117431.ZxdAFN.rst
Outdated
Show resolved
Hide resolved
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
Outdated
Show resolved
Hide resolved
…e-117431.ZxdAFN.rst Co-authored-by: Erlend E. Aasland <[email protected]>
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. |
Improve performance of
startswith
andendswith
by eliminating double work intailmatch
.Benchmark results:
Benchmark script
PyUnicode_READ
andmemcmp
PyUnicode_READ
from happening twice.