[New-bugs-announce] [issue34551] Redundant store can be removed from _PyFunction_FastCallDict

Eric Lippert report at bugs.python.org
Thu Aug 30 13:27:21 EDT 2018

New submission from Eric Lippert <ericlippert at gmail.com>:

In _PyFunction_FastCallDict we have local nk assigned to be the size of a dictionary, and then local i is assigned to twice the size of the same dictionary, and then nk is assigned to half of i, which it already is:

   nk = (kwargs != NULL) ? PyDict_GET_SIZE(kwargs) : 0;
   if (nk != 0) {
     pos = i = 0;
     while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
       i += 2;
     nk = i / 2;

I am attempting to understand the performance characteristics of this hot path, and I spent far too long trying to figure out why nk was being assigned a value it already has. :)

I propose that the redundant store be replaced with an assertion that i/2 is equal to nk.

I will submit a pull request presently.

components: Interpreter Core
messages: 324395
nosy: Eric Lippert
priority: normal
severity: normal
status: open
title: Redundant store can be removed from _PyFunction_FastCallDict
type: enhancement
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list