]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-103793: Defer formatting task name (#103767)
authorItamar Ostricher <itamarost@gmail.com>
Sat, 29 Apr 2023 15:20:09 +0000 (08:20 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 15:20:09 +0000 (08:20 -0700)
commit85c7bf5bcec07beea6064976e6199195cd34329d
tree5515f9539c36a6ac1e3e231a1a297e403d9d6928
parentfbf3596c3edadd03b5a8c659e9f27a09e5d1a051
gh-103793: Defer formatting task name (#103767)

The default task name is "Task-<counter>" (if no name is passed in during Task creation).
This is initialized in `Task.__init__` (C impl) using string formatting, which can be quite slow.
Actually using the task name in real world code is not very common, so this is wasted init.

Let's defer this string formatting to the first time the name is read (in `get_name` impl),
so we don't need to pay the string formatting cost if the task name is never read.

We don't change the order in which tasks are assigned numbers (if they are) --
the number is set on task creation, as a PyLong instead of a formatted string.

Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Doc/whatsnew/3.12.rst
Lib/test/test_asyncio/test_tasks.py
Misc/NEWS.d/next/Core and Builtins/2023-04-24-14-38-16.gh-issue-103793.kqoH6Q.rst [new file with mode: 0644]
Modules/_asynciomodule.c