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 PyObject_HasAttrString #104078

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

PyObject_HasAttrString is implemented in terms ofPyObject_GetAttrString /PyErr_Clear.
for non-existing attributes, there's significant overhead from creating an error only to clear it later.
this can be optimized by implementing it in terms ofPyObject_HasAttr.

microbenchmark

python -m pyperf timeit -s 'import _testcapihasattr_string = _testcapi.hasattr_stringclass A:  def __init__(self):    self.attr = 1a = A()' 'hasattr_string(a, "noattr")'.....................Mean +- std dev: 487 ns +- 7 ns

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