You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Combining the argument-conversion loops in _PyEval_Vector #160679
In _PyEval_Vector, positional and keyword argument values are converted to _PyStackRef in separate loops. Both loops call PyStackRef_FromPyObjectNew.
The values are consecutive in args, and total_args already includes both groups. I replaced the two loops locally with:
for (size_ti=0; i<total_args; i++) {
arguments[i] =PyStackRef_FromPyObjectNew(args[i]);
}
This removes the duplicated conversion code and the second kwnames check. Conversion order and reference ownership stay the same. _PyEvalFramePushAndInit still receives the positional count, argcount, and kwnames separately.
The test suite passes with the change.
Is there a reason to keep the positional and keyword conversions separate?
Is there a reason to keep the positional and keyword conversions separate?
P.S. Even with -O3 -march=native, the compiler (gcc-16 and clang-23) leaves these as two separate loops in the optimized IR (LLVM IR | GCC GIMPLE), including the second kwnames check and keyword-count load. This suggests a small performance optimization opportunity, rather than just a source-code cleanup.
Eliminating the redundant keyword check and merging the conversion loops saves ~6 ns per call on mixed positional/keyword vectorcalls without introducing any behavioral changes.
Activity
sergey-miryanov commentedon Oct 25, 2026
Can we measure the speedup?
ashm-dev commentedon Oct 26, 2026
Here are the benchmark numbers using
pyperfon a full PGO+LTO build.Results
mainpatchvectorcall_kw(Ran via
pyperf compare_to main.json patch.json)Benchmark script & build flags
Build configuration:
Eliminating the redundant keyword check and merging the conversion loops saves ~6 ns per call on mixed positional/keyword vectorcalls without introducing any behavioral changes.
chore: merge upstream main into pythongh-160679
eendebakpt commentedon Oct 26, 2026
@ashm-dev Can you open a PR?
ashm-dev commentedon Oct 26, 2026
@eendebakpt The changes are ready on my branch: https://github.com/ashm-dev/cpython/tree/gh-160679
I'm currently hitting the 3 open PRs limit, so I can't submit it right now. Will open the PR as soon as a slot frees up