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
_PyStackRefinstead ofPyObject *.This is necessary for the free-threaded build to support deferred references.
For the default build
_PyStackRefis just an alias forPyObject *.We should change
_PyStackRefto 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_PyStackRefs.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 & 1NULLis treated as immortal and tagged, this is the same as PyStackRef_CLOSE.Maintaining the invariant that tag
11is used for all immortal objects is a bit expensive, but can be mitigated by pushing the conversion fromPyObject *to_PyStackRefdown to a point where it is known whether an object is newly created or not.For newly created objects
PyStackRef_FromPyObjectStealMortalcan 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
_PyStackRefs in the default build. #127875_PyStackRefs inspired by HPy debug mode #128121The text was updated successfully, but these errors were encountered: