Content-Length: 268904 | pFad | https://github.com/python/cpython/issues/104066

57 Performance of attribute lookup for module objects · Issue #104066 · python/cpython · GitHub
Skip to content

Performance of attribute lookup for module objects #104066

@itamaro

Description

@itamaro

Feature or enhancement

Similar to gh-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 in gh-92216, the reason for the slowness is time spent in creating an AttributeError, which is not needed.
By adding a special case for modules (similar to the type special case in gh-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









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/104066

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy