-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
asyncio: Optimize loop.call_soon #72786
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
Comments
loop.call_soon is the central function of asyncio. Everything goes through it. Current design of asyncio.loop.call_soon makes the following checks:
Check #3 is very expensive, because it uses an 'isinstance' check. Moreover, isinstance checks against an ABC, which makes the call even slower. Attached patch makes check #3 optional and run only in debug mode. This is a very safe patch to merge. This makes asyncio another 17% (sic!) faster. In fact it becomes as fast as curio for realistic streams benchmarks. |
The patch looks good. But checking in debug mode looks very reasonable to me if it is so expensive. |
We'll update asyncio docs in 3.6 with a tutorial to focus on coroutines (not on low-level event loop). This should leave the loop API to advanced users.
Exactly. |
I didn't review the patch, but I agree with the overall approach: expensive If people are concerned by the removal of the check by default, we should |
Patch 3 LGTM. |
call_soon3.patch: LGTM. It enhances error messages (fix the method name) and should make asyncio faster. |
maybe make dirty hack and check hasattr(callback, 'send') ? |
Will commit this soon.
If you schedule a coroutine object it will fail anyways, because it's not callable. |
New changeset 128ffe3c3eb9 by Yury Selivanov in branch '3.5': New changeset 4f570a612aec by Yury Selivanov in branch '3.6': New changeset 46c3eede41a6 by Yury Selivanov in branch 'default': |
Guido, Andrew, thanks for reviews! I've fixed some unittests before committing the patch. |
PS. I noticed there are a few lines different between the "upstream" repo + # Wake up the loop if the finalizer was called from On Thu, Nov 3, 2016 at 3:12 PM, Yury Selivanov <report@bugs.python.org>
|
+ # Wake up the loop if the finalizer was called from Yeah, looks like shutdown_asyncgens somehow ended up in 3.5 branch (there's no harm in it being there). I'll sync the branches. |
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: