8000 Defer string formatting in asyncio Task creation · Issue #103793 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Defer string formatting in asyncio Task creation #103793

@itamaro

Description

@itamaro

Feature or enhancement

When an asyncio Task is created without passing in a name (a common case), the init method uses a global counter to generate a task name of the form "Task-<counter>".

It is very common in applications that the task name is never read or used, and string formatting has non-negligible runtime cost, making task creation slower. It would be beneficial to defer the string formatting operation and avoid incurring that overhead during task creation.

This can be don 69F8 e by storing the counter in the task struct, and using it to lazily populate the name in the get_name method.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0