New submission from Dino Viehland <dinoviehl...@gmail.com>:

The idea here is to add a new flag to the vectorcall nargs that indicates the 
call is being awaited: _Py_AWAITED_CALL_MARKER.  This flag will allow the 
callee to know that it's being eagerly evaluated.  When the call is eagerly 
evaluated the callee can potentially avoid various amounts of overhead.  For a 
coroutine the function can avoid creating the coroutine object and instead 
returns a singleton instance of a wait handle indicating eager execution has 
occurred:
https://github.com/facebookincubator/cinder/blob/cinder/3.8/Python/ceval.c#L6617

This gives a small win by reducing the overhead of allocating the co-routine 
object.

For something like gather much more significant wins can be achieved.  If all 
of the inputs have already been computed the creation of tasks and scheduling 
of them to the event loop can be elided.  An example implementation of this is 
available in Cinder: 
https://github.com/facebookincubator/cinder/blob/cinder/3.8/Modules/_asynciomodule.c#L7103

Again the gather implementation uses the singleton wait handle object to return 
the value indicating the computation completed synchronously.

We've used this elsewhere in Cinder as well - for example if we have an 
"AsyncLazyValue" which lazily performs a one-time computation of a value   and 
caches it.  Therefore the common case becomes that the value is already 
available, and the await can be performed without allocating any intermediate 
values.

----------
assignee: dino.viehland
messages: 414782
nosy: Mark.Shannon, carljm, dino.viehland, gvanrossum, itamaro
priority: normal
severity: normal
stage: needs patch
status: open
title: Enable informing callee it's awaited via vector call flag
type: performance
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46965>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to