Skip to content

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

Closed

Description

@1st1
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']

    Activity

    1. 1st1 commented on Dec 18, 2017

      @1st1
      MemberAuthor

      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.

    2. changed the title [-]Optimize asyncio.iscoroutine() for non-native coroutines[/-] [+]Optimize asyncio.iscoroutine() and loop.create_task() for non-native coroutines[/+] on Dec 18, 2017
    3. 1st1 commented on Dec 19, 2017

      @1st1
      MemberAuthor

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

    4. added
      performance
      on Dec 19, 2017
    5. 1st1 commented on Dec 23, 2017

      @1st1
      MemberAuthor

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

    6. 1st1 commented on Dec 23, 2017

      @1st1
      MemberAuthor

      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

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)performancetopic-asyncio

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions