Skip to content
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

Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines #76538

Closed
1st1 opened this issue Dec 18, 2017 · 4 comments
Closed
Labels
3.7 (EOL) end of life performance Performance or resource usage topic-asyncio

Comments

@1st1
Copy link
Member

1st1 commented Dec 18, 2017

BPO 32357
Nosy @asvetlov, @1st1
PRs
  • bpo-32357: Optimize asyncio.iscoroutine() for non-native coroutines #4915
  • bpo-32357: Fix tests in refleak mode #4989
  • bpo-32357: Use PySet_GET_SIZE macro in _is_coroutine() from _asynciomodule.c  #4990
  • Files
  • bench.py
  • 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:

    assignee = None
    closed_at = <Date 2017-12-19.12:19:04.774>
    created_at = <Date 2017-12-18.05:33:40.749>
    labels = ['expert-asyncio', '3.7', 'performance']
    title = 'Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines'
    updated_at = <Date 2017-12-23.20:06:48.846>
    user = 'https://github.com/1st1'

    bugs.python.org fields:

    activity = <Date 2017-12-23.20:06:48.846>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-19.12:19:04.774>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2017-12-18.05:33:40.749>
    creator = 'yselivanov'
    dependencies = []
    files = ['47337']
    hgrepos = []
    issue_num = 32357
    keywords = ['patch']
    message_count = 4.0
    messages = ['308515', '308631', '308960', '308967']
    nosy_count = 2.0
    nosy_names = ['asvetlov', 'yselivanov']
    pr_nums = ['4915', '4989', '4990']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue32357'
    versions = ['Python 3.7']

    @1st1
    Copy link
    Member Author

    1st1 commented Dec 18, 2017

    asyncio.Task now uses asyncio.iscoroutine() to give a comprehensible error if a user creates a Task for a non-awaitable type.

    The problem is that iscoroutine() is quite expensive for non-native coroutines (like the ones compiled with Cython), as it uses isinstance(obj, collections.abc.Coroutine) call. This makes 'loop.create_task(cython_coroutine)' 20% slower than 'loop.create_task(python_coroutine)'.

    The PR adds a positive type cache to the iscoroutine() function and to the asyncio.Task C implementation. Both caches make 'loop.create_task()' equally fast for all kinds of coroutines.

    @1st1 1st1 changed the title Optimize asyncio.iscoroutine() for non-native coroutines Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines Dec 18, 2017
    @1st1
    Copy link
    Member Author

    1st1 commented Dec 19, 2017

    New changeset a9d7e55 by Yury Selivanov in branch 'master':
    bpo-32357: Optimize asyncio.iscoroutine() for non-native coroutines (bpo-4915)
    a9d7e55

    @1st1 1st1 closed this as completed Dec 19, 2017
    @1st1 1st1 added the performance Performance or resource usage label Dec 19, 2017
    @1st1
    Copy link
    Member Author

    1st1 commented Dec 23, 2017

    New changeset 558aa30 by Yury Selivanov in branch 'master':
    bpo-32357: Fix tests in refleak mode (bpo-4989)
    558aa30

    @1st1
    Copy link
    Member Author

    1st1 commented Dec 23, 2017

    New changeset 0f47fa2 by Yury Selivanov (Andrew Svetlov) in branch 'master':
    bpo-32357: Use PySet_GET_SIZE macro in _is_coroutine() from _asynciomodule.c (bpo-4990)
    0f47fa2

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life performance Performance or resource usage topic-asyncio
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant