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

gh-140009: Optimize dict object by replacing PyTuple_Pack with PyTuple_FromArray by rashes2006 · Pull Request #144529 · python/cpython · GitHub

Repository navigation

gh-140009: Optimize dict object by replacing PyTuple_Pack with PyTuple_FromArray - #144529

Closed
rashes2006 wants to merge 6 commits into
python:mainfrom
rashes2006:refactor-dict-tuple-opt
Closed

rashes2006 wants to merge 6 commits into
python:mainfrom
rashes2006:refactor-dict-tuple-opt

Conversation

rashes2006 commented Feb 5, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown

Fixes: #144529

Summary

This PR replaces PyTuple_Pack with PyTuple_FromArray in Objects/dictobject.c for creating small tuples (size 2).

PyTuple_FromArray is more efficient than PyTuple_Pack because it avoids the overhead of variadic arguments (va_args) processing by taking a pointer to a pre-allocated array of PyObject*.

Changes

  • dictiter_new: Replaced PyTuple_Pack(2, Py_None, Py_None) with PyTuple_FromArray using a stack-allocated array.
  • dictitems_xor_lock_held: Replaced PyTuple_Pack(2, key, val2) with PyTuple_FromArray.

Performance Impact

This is part of a general effort to optimize small tuple creation across the codebase. Replacing PyTuple_Pack with PyTuple_FromArray for small, fixed-size tuples reduces call overhead.

python-cla-bot Bot commented Feb 5, 2026 •
edited
Loading

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

bedevere-app Bot commented Feb 5, 2026

Copy link
Copy Markdown

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 skip news label instead.

bedevere-app Bot commented Feb 5, 2026

Copy link
Copy Markdown

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 skip news label instead.

StanFromIreland changed the title Optimize dict object by replacing PyTuple_Pack with PyTuple_FromArray gh-140009: Optimize dict object by replacing PyTuple_Pack with PyTuple_FromArray Feb 5, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL