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.ensure_future by reordering if conditions #77686

Closed
jimmylai mannequin opened this issue May 14, 2018 · 4 comments
Closed

Optimize asyncio.ensure_future by reordering if conditions #77686

jimmylai mannequin opened this issue May 14, 2018 · 4 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life performance Performance or resource usage topic-asyncio

Comments

@jimmylai
Copy link
Mannequin

jimmylai mannequin commented May 14, 2018

BPO 33505
Nosy @asvetlov, @1st1, @jimmylai
PRs
  • bpo-33505: Optimize asyncio.ensure_future by reordering if conditions #6832
  • bpo-33505: Optimize asyncio.ensure_future by reordering if conditions #6836
  • [3.7] bpo-33505: Optimize asyncio.ensure_future by reordering if conditions (GH-6836) #7162
  • Files
  • ensure_future_benchmark.py: ./python.exe ensure_furture_benchmark.py -o ensure_future_optimized.json
  • 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 2018-05-28.19:14:26.685>
    created_at = <Date 2018-05-14.20:45:32.923>
    labels = ['3.8', 'expert-asyncio', '3.7', 'performance']
    title = 'Optimize asyncio.ensure_future by reordering if conditions'
    updated_at = <Date 2018-05-28.19:14:26.684>
    user = 'https://github.com/jimmylai'

    bugs.python.org fields:

    activity = <Date 2018-05-28.19:14:26.684>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-28.19:14:26.685>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2018-05-14.20:45:32.923>
    creator = 'jimmylai'
    dependencies = []
    files = ['47591']
    hgrepos = []
    issue_num = 33505
    keywords = ['patch']
    message_count = 4.0
    messages = ['316572', '316656', '317887', '317899']
    nosy_count = 3.0
    nosy_names = ['asvetlov', 'yselivanov', 'jimmylai']
    pr_nums = ['6832', '6836', '7162']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue33505'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @jimmylai
    Copy link
    Mannequin Author

    jimmylai mannequin commented May 14, 2018

    ensure_future converts the input as future if it's not already a future.
    The condition is the following:

    if futures.isfuture(coro_or_future):
        ...
    elif coroutines.iscoroutine(coro_or_future):
        ...
    elif inspect.isawaitable(coro_or_future):
        ...

    In real world, ensure_future is mostly called by run_until_complete and gather with async function call (coroutine) as input.
    We should check iscoroutine first to make it most efficient.

    @jimmylai jimmylai mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life topic-asyncio performance Performance or resource usage labels May 14, 2018
    @jimmylai
    Copy link
    Mannequin Author

    jimmylai mannequin commented May 15, 2018

    Benchmark result:
    ./python.exe -m perf compare_to ensure_future_original.json ensure_future_optimized.json
    Mean +- std dev: [ensure_future_original] 57.4 ms +- 4.0 ms -> [ensure_future_optimized] 49.3 ms +- 4.5 ms: 1.17x faster (-14%)

    @1st1
    Copy link
    Member

    1st1 commented May 28, 2018

    New changeset e549c4b by Yury Selivanov (jimmylai) in branch 'master':
    bpo-33505: Optimize asyncio.ensure_future by reordering if conditions (GH-6836)
    e549c4b

    @1st1
    Copy link
    Member

    1st1 commented May 28, 2018

    New changeset f8fdb36 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
    bpo-33505: Optimize asyncio.ensure_future by reordering if conditions (GH-6836) (bpo-7162)
    f8fdb36

    @1st1 1st1 closed this as completed May 28, 2018
    @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 3.8 (EOL) end of life performance Performance or resource usage topic-asyncio
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant