GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Performance of attribute lookup for module objects · Issue #104066 · python/cpython

Performance of attribute lookup for module objects #104066

New issue
Copy link
New issue
Copy link
Closed
#104063
Closed
Performance of attribute lookup for module objects#104066
#104063
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@itamaro
itamaro
opened on May 1, 2023
Issue body actions

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

  • gh-104066: Improve performance of hasattr for module objects #104063

Activity

  1. itamaro
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on May 1, 2023
  2. itamaro
    added a commit that references this issue on May 1, 2023

    pythongh-104066: Improve performance of hasattr for module objects

    bb1fce4
  3. arhadthedev
    added
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on May 2, 2023
  4. carljm
    closed this as completedin #104063on May 4, 2023
  5. carljm
    added a commit that references this issue on May 4, 2023

    gh-104066: Improve performance of hasattr for module objects (#104063)

    fdcb49c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.