Use tagged pointers on the stack in the default build. #127705
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-feature
A feature request or enhancement
Currently all references to objects in frameobjects use
_PyStackRef
instead ofPyObject *
.This is necessary for the free-threaded build to support deferred references.
For the default build
_PyStackRef
is just an alias forPyObject *
.We should change
_PyStackRef
to use proper tagged pointers in the default build for two important reasons:My initial implementation is 0.8% slower, although I'd like to get that closer to 0 before merging anything. There is some speedup in the GC due to streamlined immortality checks, and some slowdown due to increased overhead of turning new
PyObject *
references into_PyStackRef
s.This small slowdown will allow us a large speedup (maybe more than 5%) as we can do the following:
LOAD_
instructions in the interpreter.The tagging scheme:
This tagging scheme is chosen as it provides the best performance for the most common operations:
ptr & 1
NULL
is treated as immortal and tagged, this is the same as PyStackRef_CLOSE.Maintaining the invariant that tag
11
is used for all immortal objects is a bit expensive, but can be mitigated by pushing the conversion fromPyObject *
to_PyStackRef
down to a point where it is known whether an object is newly created or not.For newly created objects
PyStackRef_FromPyObjectStealMortal
can be used which performs no immortality check.00
, or01
. This is OK as immortal refcounts have a huge margin of error and the number of possible references to one of these immortal objects is very small.Linked PRs
_PyStackRef
s in the default build. #127875_PyStackRef
s inspired by HPy debug mode #128121The text was updated successfully, but these errors were encountered: