You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2022-04-06.03:19:51.278>created_at=<Date2022-03-14.04:57:38.385>labels= ['interpreter-core', '3.11', 'performance']
title='Streamline list.append for the common case'updated_at=<Date2022-04-06.03:19:51.277>user='https://github.com/sweeneyde'
list_resize is a long function that probably won't get inlined. But for the vast majority of cases in list.append, we just need to check whether the list is big enough (not whether it's small enough, or whether it's null or the wrong type), then insert and update the size. This can be inlined, with an actual call only taking place whenever we need to resize.
We can also add a reference-consuming version of PyList_Append to elide an INCREF/DECREF pair.
Activity
sweeneyde commentedon Mar 14, 2022
list_resize is a long function that probably won't get inlined. But for the vast majority of cases in list.append, we just need to check whether the list is big enough (not whether it's small enough, or whether it's null or the wrong type), then insert and update the size. This can be inlined, with an actual call only taking place whenever we need to resize.
We can also add a reference-consuming version of PyList_Append to elide an INCREF/DECREF pair.
methane commentedon Mar 14, 2022
Hmm. Would you measure benefit from inlining and skipping incref/decref separately?
If benefit of inlining is very small, making _PyList_AppendTakeRef() as regular internal API looks better to me.
sweeneyde commentedon Mar 14, 2022
The attached _PyList_AppendTakeRef.diff has the ceval.c, but this implementation:
Results:
methane commentedon Mar 16, 2022
Thank you. I agree that inlining is worth enough.
But we already inlined too many functions in ceval and there is an issue caused by it... (bpo-45116)
markshannon commentedon Apr 1, 2022
New changeset a0ea7a1 by Dennis Sweeney in branch 'main':
bpo-47009: Streamline list.append for the common case (GH-31864)
a0ea7a1
markshannon commentedon Apr 5, 2022
New changeset 6c6e040 by Dennis Sweeney in branch 'main':
bpo-47009: Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP (GH-32239)
6c6e040
tiran commentedon Apr 5, 2022
New changeset 9e88b57 by Christian Heimes in branch 'main':
bpo-47009: Fix assert on big endian (GH-32332)
9e88b57
sweeneyde commentedon Apr 6, 2022
Buildbots are passing, so I'm closing this. Thanks for the catch and fix!