Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 3 commits intopython:mainfromvstinner:optimize_unicode_eq
Oct 8, 2024

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedOct 8, 2024
edited by bedevere-appbot
Loading

  • Cleanup unicode_compare_eq() code.
  • Copy unicode_compare_eq() code in unicode_eq(): the two functions are now identical.

* Cleanup unicode_compare_eq() code.* Copy unicode_compare_eq() code in unicode_eq(): the two functions  are now identical.
@vstinner
Copy link
MemberAuthor

Microbenchmark:

importpyperfimport_testcapistr1="a"*10str2=str1.encode().decode()ifstr2isstr1:raiseExceptionrunner=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):

_PyUnicode_EQ: Mean +- std dev: 7.45 ns +- 0.02 ns_PyUnicode_Equal: Mean +- std dev: 7.44 ns +- 0.02 ns

The performance is the same.

@vstinner
Copy link
MemberAuthor

cc@serhiy-storchaka

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why changeunicode_compare_eq()?

@vstinner
Copy link
MemberAuthor

For comparison, results on the main branch, also with PGO+LTO:

_PyUnicode_EQ: Mean +- std dev: 8.52 ns +- 0.02 ns_PyUnicode_Equal: Mean +- std dev: 7.45 ns +- 0.02 ns

@vstinner
Copy link
MemberAuthor

Why change unicode_compare_eq()?

I like to reduce the scope of variables by only declaring them where they are first assigned.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a 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 aboutunique_eq(), change only it. Otherwise simply useunique_eq() instead ofunique_compare_eq(). There are no reasons to have two identical static functions with different names.

@vstinner
Copy link
MemberAuthor

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.

@serhiy-storchaka
Copy link
Member

If you plan to removeunicode_compare_eq(), do not make cosmetic changes to it.

s/unicode_compare_eq/unicode_eq/

@vstinner
Copy link
MemberAuthor

If you plan to remove unicode_compare_eq(), do not make cosmetic changes to it.

As you wish: I reverted unicode_compare_eq() changes.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a 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.

@vstinnervstinner merged commitc203955 intopython:mainOct 8, 2024
37 checks passed
@vstinnervstinner deleted the optimize_unicode_eq branchOctober 8, 2024 14:25
@vstinner
Copy link
MemberAuthor

Merged, thanks for reviews.

Follow-up PR:#125114 removes _PyUnicode_EQ().

efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull requestOct 9, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@skirpichevskirpichevskirpichev left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@serhiy-storchaka@skirpichev

[8]ページ先頭

©2009-2025 Movatter.jp