-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-124502: Optimize unicode_eq() #125105
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-124502: Optimize unicode_eq() #125105
Conversation
vstinner
commented
Oct 8, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Cleanup unicode_compare_eq() code.
- Copy unicode_compare_eq() code in unicode_eq(): the two functions are now identical.
- Issue: [C API] Add PyUnicode_Equal() function #124502
* Cleanup unicode_compare_eq() code. * Copy unicode_compare_eq() code in unicode_eq(): the two functions are now identical.
Microbenchmark: import pyperf
import _testcapi
str1 = "a" * 10
str2 = str1.encode().decode()
if str2 is str1:
raise Exception
runner = pyperf.Runner()
runner.bench_time_func('_PyUnicode_EQ', _testcapi.bench_eq, str1, str2)
runner.bench_time_func('_PyUnicode_Equal', _testcapi.bench__equal, str1, str2) Result on Python built with PGO+LTO (without CPU isolation):
The performance is the same. |
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.
Why change unicode_compare_eq()
?
For comparison, results on the main branch, also with PGO+LTO:
|
I like to reduce the scope of variables by only declaring them where they are first assigned. |
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.
If this PR is only about unique_eq()
, change only it. Otherwise simply use unique_eq()
instead of unique_compare_eq()
. There are no reasons to have two identical static functions with different names.
Once this PR will be merged, I plan to write a following PR to remove unicode_compare_eq() and _PyUnicode_EQ(). I limited this PR to optimizing unicode_eq() to be able to measure the speedup. Otherwise, it was too difficult to measure it. |
If you plan to remove s/unicode_compare_eq/unicode_eq/ |
As you wish: I reverted unicode_compare_eq() changes. |
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.
LGTM. Although I think that #125070 was clearer, because it shown the larger picture.
Merged, thanks for reviews. Follow-up PR: #125114 removes _PyUnicode_EQ(). |