Skip to content

bpo-46939: Specialize calls to Python classes (POSTCALL edition) #31936

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
43112e0
Specialize calls to Python classes
Fidget-Spinner Mar 6, 2022
09a7180
Add news
Fidget-Spinner Mar 6, 2022
d74d294
Fix segfaults, refleaks, readjust sys tests size
Fidget-Spinner Mar 6, 2022
0583f6b
fix refleak on frame exit due to exception
Fidget-Spinner Mar 6, 2022
bb78e9c
Use non-function pointer since it's faster
Fidget-Spinner Mar 6, 2022
b570e92
Address Jelle's review (use vectorcall for new)
Fidget-Spinner Mar 7, 2022
efad70f
Address Mark's reviews (remove func version check)
Fidget-Spinner Mar 7, 2022
4d6a06b
Use a macro for passing self
Fidget-Spinner Mar 7, 2022
5b526af
Merge remote-tracking branch 'upstream/main' into specialize_py_class…
Fidget-Spinner Mar 8, 2022
de3a406
Use inline caching
Fidget-Spinner Mar 8, 2022
30a0659
Regenerate frozenmain
Fidget-Spinner Mar 8, 2022
db09eef
Fix test_dis
Fidget-Spinner Mar 8, 2022
0d7f59e
Merge remote-tracking branch 'upstream/main' into specialize_py_class…
Fidget-Spinner Mar 8, 2022
28f9dbb
Drop generators from specialization
Fidget-Spinner Mar 8, 2022
b8b1f84
broken attempt at POSTCALL
Fidget-Spinner Mar 10, 2022
f3763a8
fix stack bugs (pop only AFTER all the deopts)
Fidget-Spinner Mar 14, 2022
fd94b86
regen test_frozenmain
Fidget-Spinner Mar 14, 2022
afbfa99
rollback generator changes
Fidget-Spinner Mar 16, 2022
33caa29
Fix test_dis, add dis docs
Fidget-Spinner Mar 16, 2022
7ea82da
Merge branch 'main' of https://github.com/python/cpython into special…
Fidget-Spinner Apr 6, 2022
49f5edf
regen test_frozenmain
Fidget-Spinner Apr 6, 2022
ea60df0
Fix test_dis
Fidget-Spinner Apr 6, 2022
a51be54
add missing line
Fidget-Spinner Apr 6, 2022
ad6bd6c
Merge branch 'main' of https://github.com/python/cpython into special…
Fidget-Spinner Apr 6, 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
8 changes: 8 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,14 @@ iterations of the loop.
.. versionadded:: 3.11


.. opcode:: POSTCALL

Suffixes :opcode:`CALL`. Logically this is a no op.
It exists to enable effective specialization of calls.

.. versionadded:: 3.11


.. opcode:: PUSH_NULL

Pushes a ``NULL`` to the stack.
Expand Down
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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
1 change: 1 addition & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef struct {

typedef struct {
_Py_CODEUNIT counter;
_Py_CODEUNIT type_version[2];
} _PyPrecallCache;

#define INLINE_CACHE_ENTRIES_PRECALL CACHE_ENTRIES(_PyPrecallCache)
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern PyStatus _PyTypes_InitSlotDefs(void);

extern void _PyStaticType_Dealloc(PyTypeObject *type);

extern PyObject *_PyObject_New_Vector(PyTypeObject *type,
PyObject *const *args, Py_ssize_t nargs, PyObject *kwds);

#ifdef __cplusplus
}
Expand Down
146 changes: 75 additions & 71 deletions Include/opcode.h

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

3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a6 3490 (remove JUMP_IF_NOT_EXC_MATCH, add CHECK_EXC_MATCH)
# Python 3.11a6 3491 (remove JUMP_IF_NOT_EG_MATCH, add CHECK_EG_MATCH,
# add JUMP_BACKWARD_NO_INTERRUPT, make JUMP_NO_INTERRUPT virtual)
# Python 3.11a6 3492 (Specialize PRECALL for Python classes)

# Python 3.12 will start with magic number 3500

Expand All @@ -414,7 +415,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3491).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3492).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
4 changes: 3 additions & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def jabs_op(name, op, entries=0):
def_op('CACHE', 0)
def_op('POP_TOP', 1)
def_op('PUSH_NULL', 2)
def_op('POSTCALL', 3)

def_op('NOP', 9)
def_op('UNARY_POSITIVE', 10)
Expand Down Expand Up @@ -191,7 +192,7 @@ def jabs_op(name, op, entries=0):
def_op('SET_UPDATE', 163)
def_op('DICT_MERGE', 164)
def_op('DICT_UPDATE', 165)
def_op('PRECALL', 166, 1)
def_op('PRECALL', 166, 3)

def_op('CALL', 171, 4)
def_op('KW_NAMES', 172)
Expand Down Expand Up @@ -307,6 +308,7 @@ def jabs_op(name, op, entries=0):
"PRECALL_NO_KW_TUPLE_1",
"PRECALL_NO_KW_TYPE_1",
"PRECALL_PYFUNC",
"PRECALL_PY_CLASS",
],
"RESUME": [
"RESUME_QUICK",
Expand Down
Loading