Skip to content

Regular object layout #80

@markshannon

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions