Skip to content

GH-91095: Specialize calls to normal python classes #93221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
158010e
Spacialize calls to normal Python classes.
markshannon Dec 8, 2021
4f74e30
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Dec 15, 2021
a62f708
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jan 4, 2022
c607dfe
Don't change magic number.
markshannon Jan 5, 2022
b9ee4f9
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jan 5, 2022
e6002c4
Add news
markshannon Jan 5, 2022
2254d06
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jan 5, 2022
2f32fcd
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon May 24, 2022
697bc4f
Fix line table for init cleanup function.
markshannon May 25, 2022
c6f8f8e
Fix refleaks
markshannon May 25, 2022
5edb423
Add news
markshannon May 25, 2022
7166184
Update summarize stats script.
markshannon May 25, 2022
3260c42
Fix stats for inlined py calls
markshannon May 25, 2022
641c46e
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon May 25, 2022
6749242
Remove duplicate news item.
markshannon May 25, 2022
426b5b3
Tidy up
markshannon May 25, 2022
e70711a
Fix decrefs
markshannon May 27, 2022
70e3e06
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon May 27, 2022
4a58e68
Make it explicit that shim frame is artificial and should not show up…
markshannon May 27, 2022
7c0876c
Fixup sys._getframe
markshannon May 27, 2022
365fceb
Add explanatory comment to CALL_NO_KW_ALLOC_AND_ENTER_INIT.
markshannon Jun 7, 2022
1ee2f1c
Add test for tracing when quickening calls to Python classes.
markshannon Jun 7, 2022
b75b1aa
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jun 7, 2022
224c4ac
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jun 20, 2022
f368a30
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jun 21, 2022
b5cf97d
Remove is_artificial and use _co_firsttraceable instead.
markshannon Jun 29, 2022
ba83e76
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jun 29, 2022
8a5c7e6
Explain unusual structure of _Py_InitCleanupFunc code.
markshannon Jun 29, 2022
80444e4
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jul 19, 2022
cd41308
Do not include incomplete frames in tracebacks.
markshannon Jul 19, 2022
9ffd10d
Make init-cleanup function per-interpreter, rather than global.
markshannon Jul 25, 2022
3645ea4
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Jul 25, 2022
255e1c1
Fix whitespace
markshannon Jul 25, 2022
72e50e0
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Aug 24, 2022
5b94ad6
Merge branch 'main' into specialize-calls-to-normal-python-classes
markshannon Aug 25, 2022
ff3ffef
Use code object instead of function as trampoline.
markshannon Aug 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct _typeobject {
* by code other than the specializer and interpreter. */
struct _specialization_cache {
PyObject *getitem;
PyObject *init;
};

/* The *real* layout of a type object when allocated on the heap */
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct callable_cache {
PyObject *len;
PyObject *list_append;
PyObject *object__getattribute__;
/* This is a strong reference */
PyCodeObject *init_cleanup;
};

/* "Locals plus" for a code object is the set of locals + cell vars +
Expand Down
35 changes: 33 additions & 2 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,27 @@ static inline void _PyFrame_StackPush(_PyInterpreterFrame *f, PyObject *value) {

void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);

static inline void
_PyFrame_InitializeSpecialsTrampoline(
_PyInterpreterFrame *frame, PyCodeObject *code, int stackdepth, int start)
{
frame->f_funcobj = Py_NewRef(Py_None);
frame->f_code = (PyCodeObject *)Py_NewRef(code);
#ifdef Py_DEBUG
frame->f_builtins = NULL;
frame->f_globals = NULL;
#endif
frame->f_locals = NULL;
frame->stacktop = code->co_nlocalsplus + stackdepth;
frame->frame_obj = NULL;
frame->prev_instr = _PyCode_CODE(code) + start;
frame->is_entry = false;
frame->owner = FRAME_OWNED_BY_THREAD;
}

/* Consumes reference to func and locals */
static inline void
_PyFrame_InitializeSpecials(
_PyFrame_InitializeSpecialsFromFunction(
_PyInterpreterFrame *frame, PyFunctionObject *func,
PyObject *locals, PyCodeObject *code)
{
Expand Down Expand Up @@ -213,7 +231,20 @@ _PyFrame_PushUnchecked(PyThreadState *tstate, PyFunctionObject *func)
_PyInterpreterFrame *new_frame = (_PyInterpreterFrame *)tstate->datastack_top;
tstate->datastack_top += code->co_framesize;
assert(tstate->datastack_top < tstate->datastack_limit);
_PyFrame_InitializeSpecials(new_frame, func, NULL, code);
_PyFrame_InitializeSpecialsFromFunction(new_frame, func, NULL, code);
return new_frame;
}

/* Pushes a trampoline frame without checking for space.
* Must be guarded by _PyThreadState_HasStackSpace() */
static inline _PyInterpreterFrame *
_PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int stackdepth, int start)
{
CALL_STAT_INC(frames_pushed);
_PyInterpreterFrame *new_frame = (_PyInterpreterFrame *)tstate->datastack_top;
tstate->datastack_top += code->co_framesize;
assert(tstate->datastack_top < tstate->datastack_limit);
_PyFrame_InitializeSpecialsTrampoline(new_frame, code, stackdepth, start);
return new_frame;
}

Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ static inline int _PyType_SUPPORTS_WEAKREFS(PyTypeObject *type) {
}

extern PyObject* _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems);
PyObject *_PyType_NewManagedObject(PyTypeObject *type);

extern int _PyObject_InitializeDict(PyObject *obj);
int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);
extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
PyObject *name, PyObject *value);
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
Expand Down
56 changes: 28 additions & 28 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading