[issue39028] ENH: Fix performance issue in keyword extraction

Sebastian Berg report at bugs.python.org
Wed Dec 11 23:04:55 EST 2019


New submission from Sebastian Berg <sebastian at sipsolutions.net>:

The keyword argument extraction/finding function seems to have a performance bug/enhancement (unless I am missing something here). It reads:


```
    for (i=0; i < nkwargs; i++) {
        PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);

        /* ptr==ptr should match in most cases since keyword keys
           should be interned strings */
        if (kwname == key) {
            return kwstack[i];
        }
        assert(PyUnicode_Check(kwname));
        if (_PyUnicode_EQ(kwname, key)) {
            return kwstack[i];
        }
    }
```

However, it should be split into two separate for loops, using the `PyUnicode_EQ` check only if it failed for _all_ other arguments.

I will open a PR for this (it seemed like a bpo number is wanted for almost everything.

----------
components: C API
messages: 358287
nosy: seberg
priority: normal
severity: normal
status: open
title: ENH: Fix performance issue in keyword extraction
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39028>
_______________________________________


More information about the Python-bugs-list mailing list