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

Refactor dict tuple opt#144530

Closed
rashes2006 wants to merge 2 commits into
python:mainpython/cpython:mainfrom
rashes2006:refactor-dict-tuple-optrashes2006/cpython:refactor-dict-tuple-optCopy head branch name to clipboard
Closed

Refactor dict tuple opt#144530
rashes2006 wants to merge 2 commits into
python:mainpython/cpython:mainfrom
rashes2006:refactor-dict-tuple-optrashes2006/cpython:refactor-dict-tuple-optCopy head branch name to clipboard

Conversation

@rashes2006

@rashes2006 rashes2006 commented Feb 5, 2026

Copy link
Copy Markdown

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

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

python-cla-bot Bot commented Feb 5, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@rashes2006 rashes2006 force-pushed the refactor-dict-tuple-opt branch 2 times, most recently from 7dbd163 to 174a82b Compare February 5, 2026 22:43
@rashes2006 rashes2006 closed this Feb 5, 2026
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

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