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 — hasattr() performance is bad on a slot that has no value · Issue #157840 · python/cpython

hasattr() performance is bad on a slot that has no value #157840

New issue
Copy link
New issue
Copy link
Closed
Closed
hasattr() performance is bad on a slot that has no value#157840
Copy link
Assignees
ZeroIntensity
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

@uwu-crj
uwu-crj
opened on Sep 20, 2026
Issue body actions

Bug report

Bug description:

Compare these two timeit invocations:

$ python3.14 -m timeit -s 'class Test: pass' -s 't = Test()' 'hasattr(t,"x")'
10000000 loops, best of 5: 33.5 nsec per loop
$ python3.14 -m timeit -s 'class Test: __slots__ = ("x",)' -s 't = Test()' 'hasattr(t,"x")'
1000000 loops, best of 5: 241 nsec per loop

Observe that in the case where Test.x is a slot, hasattr takes 241 ns to return False while it only takes 33.5 ns when there is no Test.x slot.

Peter Bierma advised me to file an issue when I asked about this in Discourse.

CPython versions tested on:

3.14, 3.13, 3.12

Operating systems tested on:

Linux

Linked PRs

  • gh-157840: Special-case member descriptors when using hasattr #157866

Activity

  1. uwu-crj
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 20, 2026
  2. aisk
    added
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 20, 2026
  3. ZeroIntensity
    self-assigned this
    on Sep 20, 2026
  4. ZeroIntensity
    added a commit that references this issue on Sep 20, 2026

    gh-157840: Special-case member descriptors when using `hasattr` (GH-1…

    41d0922
  5. ZeroIntensity
    closed this as completedon Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ZeroIntensity
    ZeroIntensity

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 01402520 — 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.