GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Optimize `asyncio.get_running_loop` · Issue #100363 · python/cpython

Optimize asyncio.get_running_loop #100363

New issue
Copy link
New issue
Copy link
Closed
Closed
Optimize asyncio.get_running_loop#100363
Copy link
Assignees
kumaraditya303
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asyncio

Description

@kumaraditya303
kumaraditya303
opened on Dec 20, 2022
Issue body actions

asyncio.get_running_loop is one of the most performance critical functions in asyncio. With #66285 the running loop can be reset in the fork handler thereby avoiding the need for the getpid checks. The whole running loop holder object is unnecessary now and adds up unnecessary dependent memory loads.

Benchmark:

import asyncio
from pyperf import Runner

async def main():
    for i in range(10000):
        asyncio.get_running_loop()


runner = Runner()
runner.bench_async_func("main", main)

Result:

Benchmark base patch
main 5.03 ms 328 us: 15.33x faster

The numbers speak for themselves.

Linked PRs

  • GH-100363: Speed up asyncio.get_running_loop #100364

Activity

  1. kumaraditya303
    added
    performancePerformance or resource usagePerformance or resource usage
    topic-asyncio
    3.12only security fixesonly security fixes
    on Dec 20, 2022
  2. kumaraditya303
    self-assigned this
    on Dec 20, 2022
  3. kumaraditya303
    added this to asyncioon Dec 20, 2022
  4. kumaraditya303
    moved this to Todo in asyncioon Dec 20, 2022
  5. gvanrossum commented on Dec 20, 2022

    @gvanrossum
    gvanrossum
    on Dec 20, 2022
    Member
    More actions

    asyncio.get_running_loop is one of the most performance critical functions in asyncio.

    Do you have data about this? Does it show up in profiles of real functions, or do you have call counts or whatever? Usually I imagine the call is followed by a much more expensive computation.

  6. kumaraditya303 commented on Dec 20, 2022

    @kumaraditya303
    kumaraditya303
    on Dec 20, 2022
    ContributorAuthor
    More actions

    This is based upon call counts and the fact that most functions now internally call this function as loop argument was removed from most asyncio APIs.

  7. gvanrossum commented on Dec 20, 2022

    @gvanrossum
    gvanrossum
    on Dec 20, 2022
    Member
    More actions

    Okay, makes sense.

  8. kumaraditya303
    added a commit that references this issue on Dec 21, 2022

    GH-100363: Speed up `asyncio.get_running_loop` (#100364)

    4994f24
  9. kumaraditya303
    closed this as completedon Dec 21, 2022
  10. Repository owner moved this from Todo to Done in asyncioon Dec 21, 2022
  11. iritkatriel
    added a commit that references this issue on Dec 28, 2022

    Merged main into regmachine branch (#50)

    fdc73cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kumaraditya303
    kumaraditya303

Labels

3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asyncio

Projects

  • asyncio
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.