{{ message }}
gh-150942: Speed up asyncio Future.remove_done_callback#153013
Open
muhamedfazalps wants to merge 1 commit into
Open
gh-150942: Speed up asyncio Future.remove_done_callback#153013muhamedfazalps wants to merge 1 commit into
muhamedfazalps wants to merge 1 commit into
Conversation
Use _PyList_AppendTakeRef instead of PyList_Append to avoid an extra incref/decref pair when compaction appends callbacks to the new list. The item is already owned (Py_INCREF was called earlier in the loop), so _PyList_AppendTakeRef takes ownership of that reference directly without incrementing it again.
|
The following commit authors need to sign the Contributor License Agreement: |
Member
|
Please, we need to see benchmarks and how it improved the resutl. JUst changing the code is not sufficient. |
Member
|
See #150942 (comment). |
picnixz
requested changes
Jul 4, 2026
picnixz
left a comment
Member
There was a problem hiding this comment.
Please include benchmarks first on the issue, sign the CLA and add a NEWS entry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Use
_PyList_AppendTakeRefinstead ofPyList_Appendto avoid an extra incref/decref pair when compaction appends callbacks to the new list.Fixes gh-150942
Motivation
The issue lists this as a possible performance improvement:
The current code:
The item is already owned (
Py_INCREFwas called earlier), soPyList_Appendincrements the refcount and thenPy_DECREFdecrements it - an unnecessary pair.Changes
_PyList_AppendTakeReftakes ownership of the reference without incrementing it, eliminating the unnecessary incref/decref pair.Testing
Discovered during open source research. https://buymeacoffee.com/muhamedfazalps