Skip to content

"immortal" objects #14

Closed
Closed
@ericsnowcurrently

Description

@ericsnowcurrently

The idea of "immortal" objects is basically that we can skip certain operations if we know that an object will never go away. That includes objects like the singletons, small ints, and static types. There are several potential benefits to immortal objects:

  • allows immutable objects to be shared directly between interpreters (my favorite)
  • allows better copy-on-write behavior when forking
  • optimizations

(related: tagged pointers)

Prior Art

Eddie Elizondo PR (April 2020)

Early last year, Eddie Elizondo posted a PR for supporting "immortal" objects, with a focus on the interests of his team at Facebook. See:

The key changes there are in Include/object.h and Objects/object.c. Eddie's main motivation is to facilitate better copy-on-write behavior when forking. I think he showed some promising results but there were concerns about the costs under general Python usage.

Eric's Branch (December 2020)

In December I started working on the problem Python objects that are exposed via the public API (and even stable API), relative to subinterpreters not sharing the GIL. I tried out two solutions.

The first was actually very similar to Eddie's, which I didn't know about until a week or two later. Once I found Eddie's PR I made a few tweaks to my branch. See: ericsnowcurrently/cpython#9. My change should have basically no negative performance impact.

The other approach I tried was sticking a dummy object into ob_type. However, I confident that there are problems there not worth resolving. See: python/cpython@master...ericsnowcurrently:globals-immortal-objects-obtype.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions