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

GH-107803: double linked list implementation for asyncio tasks #107804

Merged
merged 35 commits into from
Jun 22, 2024

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Aug 9, 2023

@kumaraditya303 kumaraditya303 force-pushed the linked-list branch 2 times, most recently from 8d57b5a to af0280a Compare August 9, 2023 10:28
@kumaraditya303 kumaraditya303 added performance Performance or resource usage topic-asyncio 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Aug 9, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit af0280a 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 9, 2023
@kumaraditya303 kumaraditya303 marked this pull request as ready for review August 9, 2023 17:38
@kumaraditya303
Copy link
Contributor Author

I'll add Whats's New entry for this later together with other performance improvements so skipping news for now.

@gvanrossum
Copy link
Member

Is there someone else who could review this? I am currently scrambling.

Modules/_asynciomodule.c Outdated Show resolved Hide resolved
TaskObj *tail = &state->asyncio_tasks.tail;
while (head != tail)
{
if (add_one_task(state, tasks, (PyObject *)head, loop) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I understand the refcounting semantics correctly, the linked list contains borrowed references to tasks that may be already freed. (probably shouldn't happen if unregister_task is called properly, but who knows)
if that's the case, this can fail when trying to call done() in add_one_task, right?
should we add some logic here to remove freed pointers? or, if this should never happen - add an assert to check for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should never happen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an existing assert (or a new one we can add) that would catch such a scenario?

Lib/test/test_asyncio/test_tasks.py Outdated Show resolved Hide resolved
TaskObj *tail = &state->asyncio_tasks.tail;
while (head != tail)
{
if (add_one_task(state, tasks, (PyObject *)head, loop) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an existing assert (or a new one we can add) that would catch such a scenario?

@willingc
Copy link
Contributor

@kumaraditya303 @itamaro I'm going to mark this "Awaiting changes" due to the merge conflict and the amount of time that has passed since it was opened. If after fixing the changes, you would like to have this reviewed again, please ping. Thanks!

@kumaraditya303 kumaraditya303 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 21, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit c7b604c 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 21, 2024
@kumaraditya303 kumaraditya303 marked this pull request as ready for review June 22, 2024 12:55
Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me @kumaraditya303. Let's merge this and thanks for rebooting the PR.

@willingc willingc merged commit 4717aaa into python:main Jun 22, 2024
37 checks passed
@willingc
Copy link
Contributor

@kumaraditya303 I wasn't sure if we wanted to backport. Please do so if it makes sense. Thanks!

@kumaraditya303 kumaraditya303 deleted the linked-list branch June 23, 2024 04:24
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
…ythonGH-107804)

* linked list

* add tail optmiization to linked list

* wip

* wip

* wip

* more fixes

* finally it works

* add tests

* remove weakreflist

* add some comments

* reduce code duplication in _asynciomodule.c

* address some review comments

* add invariants about the state of the linked list

* add better explanation

* clinic regen

* reorder branches for better branch prediction

* Update Modules/_asynciomodule.c

* Apply suggestions from code review

Co-authored-by: Itamar Oren <[email protected]>

* fix capturing of eager tasks

* add comment to task finalization

* fix tests and couple c implmentation to c task

improved linked-list logic and more comments

* fix test

---------

Co-authored-by: Itamar Oren <[email protected]>
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…ythonGH-107804)

* linked list

* add tail optmiization to linked list

* wip

* wip

* wip

* more fixes

* finally it works

* add tests

* remove weakreflist

* add some comments

* reduce code duplication in _asynciomodule.c

* address some review comments

* add invariants about the state of the linked list

* add better explanation

* clinic regen

* reorder branches for better branch prediction

* Update Modules/_asynciomodule.c

* Apply suggestions from code review

Co-authored-by: Itamar Oren <[email protected]>

* fix capturing of eager tasks

* add comment to task finalization

* fix tests and couple c implmentation to c task

improved linked-list logic and more comments

* fix test

---------

Co-authored-by: Itamar Oren <[email protected]>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…ythonGH-107804)

* linked list

* add tail optmiization to linked list

* wip

* wip

* wip

* more fixes

* finally it works

* add tests

* remove weakreflist

* add some comments

* reduce code duplication in _asynciomodule.c

* address some review comments

* add invariants about the state of the linked list

* add better explanation

* clinic regen

* reorder branches for better branch prediction

* Update Modules/_asynciomodule.c

* Apply suggestions from code review

Co-authored-by: Itamar Oren <[email protected]>

* fix capturing of eager tasks

* add comment to task finalization

* fix tests and couple c implmentation to c task

improved linked-list logic and more comments

* fix test

---------

Co-authored-by: Itamar Oren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage skip news topic-asyncio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants