Closed
Labels
3.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
Description
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 = None
closed_at = <Date 2022-04-06.03:19:51.278>
created_at = <Date 2022-03-14.04:57:38.385>
labels = ['interpreter-core', '3.11', 'performance']
title = 'Streamline list.append for the common case'
updated_at = <Date 2022-04-06.03:19:51.277>
user = 'https://github.com/sweeneyde'bugs.python.org fields:
activity = <Date 2022-04-06.03:19:51.277>
actor = 'Dennis Sweeney'
assignee = 'none'
closed = True
closed_date = <Date 2022-04-06.03:19:51.278>
closer = 'Dennis Sweeney'
components = ['Interpreter Core']
creation = <Date 2022-03-14.04:57:38.385>
creator = 'Dennis Sweeney'
dependencies = []
files = ['50674']
hgrepos = []
issue_num = 47009
keywords = ['patch']
message_count = 8.0
messages = ['415116', '415121', '415127', '415327', '416481', '416766', '416786', '416841']
nosy_count = 4.0
nosy_names = ['christian.heimes', 'methane', 'Mark.Shannon', 'Dennis Sweeney']
pr_nums = ['31864', '32239', '32332']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue47009'
versions = ['Python 3.11']Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
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!