gh-140009: Replace PyTuple_Pack with PyTuple_FromArray in codeobject.c and _pickle.c#144829
Open
RoryGlenn wants to merge 2 commits intopython:mainfrom
Open
gh-140009: Replace PyTuple_Pack with PyTuple_FromArray in codeobject.c and _pickle.c#144829RoryGlenn wants to merge 2 commits intopython:mainfrom
RoryGlenn wants to merge 2 commits intopython:mainfrom
Conversation
…bject.c and _pickle.c
Contributor
|
Thanks for the suggestions. As explained here #140009 (comment):
Since many of your changes deal with |
bkap123
reviewed
Feb 19, 2026
| @@ -0,0 +1,3 @@ | |||
| Replace :c:func:`PyTuple_Pack` calls with :c:func:`PyTuple_FromArray` in | |||
Contributor
There was a problem hiding this comment.
This is probably not necessary since nothing really changes from the user's perspective. Just mention that performance improved, similar to the NEWS entry for #140010
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gh-140009: Replace
PyTuple_PackwithPyTuple_FromArraySummary
This PR replaces
PyTuple_Packcalls withPyTuple_FromArrayusing stack-allocated arrays in two files:Objects/codeobject.c: 11 replacements in_PyCode_ConstantKey()— called for every constant in every code object during compilation (handles bool, bytes, float, complex, tuple, frozenset, slice, and fallback branches)Modules/_pickle.c: 3 replacements infix_imports(),save_global(), andfind_class()— dictionary key construction for protocol compatibility mappingsMotivation
PyTuple_FromArrayavoids the variadic argument overhead ofPyTuple_Packby taking a C array directly. This follows the pattern established in PR #140010 (merged forObjects/listobject.c).Pattern
Note:
Py_TYPE(op)returnsPyTypeObject *, so an explicit(PyObject *)cast is needed in the array initializers forcodeobject.c.Testing
test_code,test_compile,test_peepholer,test_symtable,test_codecs,test_marshal(743 tests)test_pickle,test_pickletools(1,157 tests)- Issue: Improve performance by replacing PyTuple_Pack with PyTuple_FromArray #140009
"