FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-140009: Improve performance of list_extend_dictitems by using PyTuple_FromArray by eendebakpt · Pull Request #140010 · python/cpython · GitHub

Repository navigation

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

Merged
kumaraditya303 merged 3 commits into
python:mainfrom
eendebakpt:list_extend_dict_items
Oct 13, 2025
Merged

kumaraditya303 merged 3 commits into
python:mainfrom
eendebakpt:list_extend_dict_items

Conversation

eendebakpt commented Oct 12, 2025 •
edited
Loading

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 merged commit e6aa515 into python:main Oct 13, 2025
49 checks passed

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().

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL