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 — Better stats for `LOAD_ATTR` and `STORE_ATTR` by markshannon · Pull Request #100295 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Dec 16, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR provides better stats for LOAD_ATTR and STORE_ATTR, differentiating several class attributes.
There is a slight change to specializing behavior, but it seems to make no difference in practice.

The main change is for simple attributes of a class.

Consider

class C: 
    i = 0

c = C()
c.i

c.i is not specialized and the failure is reported as "not in dict".
i isn't in the instance's dict, but that's not the problem.
With this PR, the failure is reported as "class attr simple" which is much more informative.

The change in specialization behavior is that if an instance attribute shadows a non-data descriptor, it is no longer specialized.
This has no effect on the hit rate, which remains at 82%, but does convert some misses to deferreds.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
markshannon added 3 commits December 16, 2022 11:22
@markshannon
Don't attempt to specialize for LOAD_ATTR on instance if class has at…
db9f04f
…tribute, improve stats.
@markshannon
Further improvement to LOAD_ATTR and STORE_ATTR specialization stats.
31ad53e
@markshannon
Refine stats for LOAD_ATTR with class attribute.
05a9952
@bedevere-bot bedevere-bot added the awaiting core review label Dec 16, 2022
@markshannon markshannon added skip issue skip news labels Dec 16, 2022
@markshannon
markshannon requested a review from Fidget-Spinner December 16, 2022 15:15
@markshannon

markshannon commented Dec 16, 2022

Copy link
Copy Markdown
Member Author

https://github.com/faster-cpython/ideas/blob/main/stats/pystats-2022-12-16-faster-cpython-05a9952.md

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10 corona10 mentioned this pull request Dec 16, 2022
Finish up LOAD_ATTR specialisation #100288
Closed
1 of 2 tasks
@Fidget-Spinner

Fidget-Spinner commented Dec 16, 2022

Copy link
Copy Markdown
Member

Interesting, the change in specialisation behavior is that instead of falling through and trying to specialise dict assess, we just fail immediately right?

I'm surprised the spec failures only increased by 1%.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Dec 16, 2022

Copy link
Copy Markdown
Member Author

I think what is happening is that shadowing is rare, and is usually code that stores a default value on the class, shadowing it if a non-default value is needed on the instance.

So we tend to get a lot of misses anyway.

It is generally considered good practice to set all attributes in the __init__ method, so this case should get rarer as time goes by.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner
Fidget-Spinner approved these changes Dec 16, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Dec 16, 2022
@markshannon
markshannon merged commit 289c112 into python:main Dec 16, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Dec 16, 2022
@markshannon
markshannon deleted the better-stats-load-attr branch December 16, 2022 15:43
carljm added a commit to carljm/cpython that referenced this pull request Dec 16, 2022
@carljm
Merge branch 'main' into fastmock
2260a54
* main:
  Improve stats presentation for calls. (pythonGH-100274)
  Better stats for `LOAD_ATTR` and `STORE_ATTR` (pythonGH-100295)
  pythongh-81057: Move the Cached Parser Dummy Name to _PyRuntimeState (python#100277)
  Document that zipfile's pwd parameter is a `bytes` object (python#100209)
  pythongh-99767: mark `PyTypeObject.tp_watched` as internal use only in table (python#100271)
  Fix typo in introduction.rst (python#100266)
  pythongh-78997: AttributeError if loading fails in LibraryLoader.__getattr__
  pythonGH-100234: Set a default value for random.expovariate() (pythonGH-100235)
  Remove uninformative itertools recipe (pythonGH-100253)
  pythonGH-99767: update PyTypeObject docs for type watchers (pythonGH-99928)
  Move stats for the method cache into the `Py_STAT` machinery (pythonGH-100255)
  pythonGH-100222: fix typo _py_set_opocde -> _py_set_opcode (pythonGH-100259)
  pythonGH-100000: Cleanup and polish various watchers code (pythonGH-99998)
  pythongh-90111: Minor Cleanup for Runtime-Global Objects (pythongh-100254)
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Dec 18, 2022
@shihai1991
Merge remote-tracking branch 'origin/main' into bpo_34697
2878571
* origin/main: (1306 commits)
  Correct CVE-2020-10735 documentation (python#100306)
  pythongh-100272: Fix JSON serialization of OrderedDict (pythonGH-100273)
  pythongh-93649: Split tracemalloc tests from _testcapimodule.c (python#99551)
  Docs: Use `PY_VERSION_HEX` for version comparison (python#100179)
  pythongh-97909: Fix markup for `PyMethodDef` members (python#100089)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythonGH-98831: Add DECREF_INPUTS(), expanding to DECREF() each stack input (python#100205)
  pythongh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` (pythonGH-94469)
  pythongh-99540: Constant hash for _PyNone_Type to aid reproducibility (pythonGH-99541)
  pythongh-100039: enhance __signature__ to work with str and callables (pythonGH-100168)
  pythongh-99830: asyncio: Document returns of remove_{reader,writer} (python#100302)
  "Compound statement" docs: Fix with-statement step indexing (python#100286)
  pythonGH-90043: Handle NaNs in COMPARE_OP_FLOAT_JUMP (pythonGH-100278)
  Improve stats presentation for calls. (pythonGH-100274)
  Better stats for `LOAD_ATTR` and `STORE_ATTR` (pythonGH-100295)
  pythongh-81057: Move the Cached Parser Dummy Name to _PyRuntimeState (python#100277)
  Document that zipfile's pwd parameter is a `bytes` object (python#100209)
  pythongh-99767: mark `PyTypeObject.tp_watched` as internal use only in table (python#100271)
  Fix typo in introduction.rst (python#100266)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip issue skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@markshannon @Fidget-Spinner @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.