KEMBAR78
GH-115776: Allow any fixed sized object to have inline values by markshannon · Pull Request #123192 · python/cpython · GitHub
Skip to content

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Aug 21, 2024

Currently only objects with Py_TYPE(obj)->tp_basicsize == sizeof(PyObject) are allowed to have inline values.
This PR changes that to allow any object where all instances of the class have the same size to have inline values.

Performance is in the noise, but the stats show a clear reduction in the number of LOAD_ATTRs executed.
Oddly, the number of LOAD_ATTR_INSTANCE_VALUEs executed is roughly unchanged, the new specializations being for class attributes. Fixing the shadowing issue should improve things further and show an increase in LOAD_ATTR_INSTANCE_VALUEs.

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this stuff documented anywhere?

@markshannon
Copy link
Member Author

Is this stuff documented anywhere?

Good point.

@hauntsaninja
Copy link
Contributor

It looks like this PR broke a test in the mypyc transpiler: python/mypy#17973
I suspect it's something funky when calling PyObject_SetAttr(obj, "__dict__", {"x": 10})

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants