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-104066: Improve performance of hasattr for module objects#104063

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
carljm merged 2 commits intopython:mainfromitamaro:module-hasattr
May 4, 2023

Conversation

@itamaro
Copy link
Contributor

@itamaroitamaro commentedMay 1, 2023
edited
Loading

Fixesgh-104066

microbenchmark on main

python -m pyperf timeit -s 'import os' 'hasattr(os, "getenv")'.....................Mean +- std dev: 37.8 ns +- 1.5 ns
python -m pyperf timeit -s 'import os' 'hasattr(os, "nothing")'.....................Mean +- std dev: 541 ns +- 16 ns

microbenchmark with PR

python -m pyperf timeit -s 'import os' 'hasattr(os, "getenv")'.....................Mean +- std dev: 37.2 ns +- 2.6 ns
python -m pyperf timeit -s 'import os' 'hasattr(os, "nothing")'.....................Mean +- std dev: 55.8 ns +- 3.0 ns

the missing attr case is almost 10x faster

@carljmcarljm added the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelMay 1, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@carljm for commit8c07ffb 🤖

If you want to schedule another build, you need to add the🔨 test-with-refleak-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelMay 1, 2023
@itamaroitamaro changed the titlegh-NNNNN: Improve performance of hasattr for module objectsgh-104066: Improve performance of hasattr for module objectsMay 1, 2023
@itamaroitamaro marked this pull request as ready for reviewMay 1, 2023 23:19
Copy link
Member

@carljmcarljm left a comment

Choose a reason for hiding this comment

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

This looks fine to me; it's following the existing pattern already used to optimizehasattr for both types and normal objects, by avoiding raising and then suppressing anAttributeError.

Will leave it for a couple days before merging in case any other reviewers want to take a look.

itamaro reacted with thumbs up emoji
@carljmcarljm self-assigned thisMay 2, 2023
@arhadthedevarhadthedev added performancePerformance or resource usage interpreter-core(Objects, Python, Grammar, and Parser dirs) labelsMay 2, 2023
@carljmcarljm merged commitfdcb49c intopython:mainMay 4, 2023
@itamaroitamaro deleted the module-hasattr branchMay 4, 2023 14:51
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@carljmcarljmcarljm approved these changes

Assignees

@carljmcarljm

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Performance of attribute lookup for module objects

4 participants

@itamaro@bedevere-bot@carljm@arhadthedev

[8]ページ先頭

©2009-2025 Movatter.jp