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
Add dedicated slot for sending values #86251
Comments
|
https://bugs.python.org/issue41756 has introduced PyIter_Send as a common entrypoint for sending values however currently fast path that does not use StopIteration exception is only available for generators/coroutines. It would be quite nice if this machinery was extensible and other types (both internal and 3rd party) could opt-in into using exception-free way of returning values without needing to update the implementation of PyIter_Send. One way of solving this is adding a new slot with a signature that matches PyIter_Send. With it:
Microbenchmark to demonstrate the difference of accessing the value of fulfiled Future without and with dedicated slot: Time: 8.365560054779053 s - without the slot |
|
Vladimir, please do a follow up PR documenting Py_TPFLAGS_HAVE_AM_SEND. |
This change introduced big reference leaks: 4 tests failed: Example: $ ./python -m test test_asyncgen -R 3:3 -m test.test_asyncgen.AsyncGenAsyncioTest.test_async_gen_asyncio_03
(...)
test_asyncgen leaked [63, 63, 63] references, sum=189
(...)Please fix the leak, or revert if nobody is avaible to fix it: |
|
Investigating. The test leaks a future instance. |
|
PR for the fix is created: #23237 |
|
commit cda99b4 (HEAD -> master, upstream/master) |
|
Thanks! The change fixed the leak: $ ./python -m test -j0 -R 3:3 test_asyncgen test_coroutines test_unittest # test_asyncio
(...)
Tests result: SUCCESSI didn't run test_asyncio because the test is too slow. |
|
Thank you Victor for the report! |
|
Is anything left to do? |
I think we can close this now. |
|
Py_TPFLAGS_HAVE_AM_SEND is unnecessary and I'd like to remove it. It is not possible for type objects to have a different layout than the interpreter:
Or is there a different reason for Py_TPFLAGS_HAVE_AM_SEND? Checking it may be faster than ((Py_TYPE(x)->tp_as_async != NULL) && (Py_TYPE(x)->tp_as_async->am_send != NULL)), but I don't think the speedup is relevant. See bpo-42747 |
|
Is there documentation anywhere for the semantics of am_send? I only see the signature followed by "See PyIter_Send for details", but the doc for PyIter_Send doesn't mention am_send. In particular, it would be nice to document the relationship between PyIter_Send, am_send, and tp_iternext. |
|
I am reopening this issue since am_send never got documented here: https://docs.python.org/3/c-api/typeobj.html#async-structs |
|
It did get added to the correct docs: https://docs.python.org/3.10/c-api/typeobj.html#c.PyAsyncMethods.am_send (the 3.10 and 3.11 docs, not the 3.9 docs ;-) But as I mentioned, I feel that there could be more details about the semantics/contract. |
|
Oh, my bad. I can't find the enum values of the return type, though (PySendResult). |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: