Skip to content

Regular object layout #80

Description

@markshannon

Accessing the __dict__ of an object takes a bit of pointer chasing and computation.
The code to get the address of the __dict__ is as follows:
(assuming we have already checked whether this object can have a dict)

    Py_ssize_t dictoffset = tp->tp_dictoffset;
    if (dictoffset < 0) {
        /* Compute size of object */
        Py_ssize_t tsize = ...
        dictoffset += size;
    }
    dictptr = (PyObject **) ((char *)obj + dictoffset);

Given how often we access instance attributes, this overhead is significant

What we would like is:

    dictptr = (PyObject **) ((char *)obj + CONSTANT;

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions