Skip to content

Commit 0d12f87

Browse files
authored
gh-162350: Add AC @vectorcall for asyncio module objects (#162439)
1 parent 1330e91 commit 0d12f87

3 files changed

Lines changed: 91 additions & 12 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add ``@vectorcall`` for :class:`asyncio.Future` and :class:`asyncio.Task`
2+
constructors. The performance boost is 33% for the future creation and 15%
3+
for the task.

‎Modules/_asynciomodule.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ future_cancel(asyncio_state *state, FutureObj *fut, PyObject *msg)
872872
}
873873

874874
/*[clinic input]
875+
@vectorcall
875876
_asyncio.Future.__init__
876877
877878
*
@@ -893,7 +894,7 @@ This class is *almost* compatible with concurrent.futures.Future.
893894

894895
static int
895896
_asyncio_Future___init___impl(FutureObj *self, PyObject *loop)
896-
/*[clinic end generated code: output=9ed75799eaccb5d6 input=89af317082bc0bf8]*/
897+
/*[clinic end generated code: output=9ed75799eaccb5d6 input=28ff6d3b6c3aa828]*/
897898

898899
{
899900
return future_init(self, loop);
@@ -1734,6 +1735,7 @@ static PyType_Slot Future_slots[] = {
17341735
{Py_tp_methods, FutureType_methods},
17351736
{Py_tp_getset, FutureType_getsetlist},
17361737
{Py_tp_init, _asyncio_Future___init__},
1738+
{Py_tp_vectorcall, _asyncio_Future_vectorcall},
17371739
{Py_tp_new, PyType_GenericNew},
17381740
{Py_tp_finalize, FutureObj_finalize},
17391741

@@ -2290,6 +2292,7 @@ swap_current_task(_PyThreadStateImpl *ts, PyObject *loop, PyObject *task)
22902292
/* ----- Task */
22912293

22922294
/*[clinic input]
2295+
@vectorcall
22932296
_asyncio.Task.__init__
22942297
22952298
coro: object
@@ -2306,7 +2309,7 @@ static int
23062309
_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
23072310
PyObject *name, PyObject *context,
23082311
int eager_start)
2309-
/*[clinic end generated code: output=7aced2d27836f1a1 input=18e3f113a51b829d]*/
2312+
/*[clinic end generated code: output=7aced2d27836f1a1 input=de87c52b0800ab4b]*/
23102313
{
23112314
if (future_init((FutureObj*)self, loop)) {
23122315
return -1;
@@ -2952,6 +2955,7 @@ static PyType_Slot Task_slots[] = {
29522955
{Py_tp_methods, TaskType_methods},
29532956
{Py_tp_getset, TaskType_getsetlist},
29542957
{Py_tp_init, _asyncio_Task___init__},
2958+
{Py_tp_vectorcall, _asyncio_Task_vectorcall},
29552959
{Py_tp_new, PyType_GenericNew},
29562960
{Py_tp_finalize, TaskObj_finalize},
29572961

‎Modules/clinic/_asynciomodule.c.h‎

Lines changed: 82 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)