gh-150942: Speed up asyncio Future.remove_done_callback#153013
gh-150942: Speed up asyncio Future.remove_done_callback#153013muhamedfazalps 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.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
The following commit authors need to sign the Contributor License Agreement: |
|
Please, we need to see benchmarks and how it improved the resutl. JUst changing the code is not sufficient. |
|
See #150942 (comment). |
picnixz
left a comment
There was a problem hiding this comment.
Please include benchmarks first on the issue, sign the CLA and add a NEWS entry.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
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