Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-140009: Improve performance of list_extend_dictitems by using PyTuple_FromArray#140010

Merged
kumaraditya303 merged 3 commits into
python:mainpython/cpython:mainfrom
eendebakpt:list_extend_dict_itemseendebakpt/cpython:list_extend_dict_itemsCopy head branch name to clipboard
Oct 13, 2025
Merged

gh-140009: Improve performance of list_extend_dictitems by using PyTuple_FromArray#140010
kumaraditya303 merged 3 commits into
python:mainpython/cpython:mainfrom
eendebakpt:list_extend_dict_itemseendebakpt/cpython:list_extend_dict_itemsCopy head branch name to clipboard

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Oct 12, 2025

Copy link
Copy Markdown
Contributor

Benchmark:

import pyperf
runner = pyperf.Runner()

setup="""
d = {ii: ii+1 for ii in range(200)}
dct_items = d.items()
"""
runner.timeit(name="extend list with dict keys", stmt="l = []; l += d", setup=setup)
runner.timeit(name="extend list with dict items", stmt="l = []; l += dct_items", setup=setup)

Results:

extend list with dict items: Mean +- std dev: [main] 3.78 us +- 0.07 us -> [pr] 3.17 us +- 0.03 us: 1.19x faster

Benchmark hidden because not significant (1): extend list with dict keys

Geometric mean: 1.09x faster

The benchmark is 19% faster (extend list with dict keys is a control benchmark).

@kumaraditya303 kumaraditya303 merged commit e6aa515 into python:main Oct 13, 2025
49 checks passed
@vstinner

Copy link
Copy Markdown
Member

If PyTuple_Pack() is "inefficient", I would prefer to have a specialized PyTuple_Pack2() function (or PyTuple_MakePair()) rather than having to use the generic PyTuple_FromArray().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.