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

Performance of attribute lookup for module objects #104066

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
@itamaro

Description

@itamaro

Feature or enhancement

Similar togh-92216 (for type objects) - attribute lookup on module objects for non-existing attributes is significantly slower compared to existing attributes, as well as non-existing attributes on types and instances.

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

As ingh-92216, the reason for the slowness is time spent in creating anAttributeError, which is not needed.
By adding a special case for modules (similar to the type special case ingh-99979), this overhead can be eliminated.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp