This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients Dennis Sweeney, methane
Date 2022-03-14.10:35:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647254139.91.0.09798128077.issue47009@roundup.psfhosted.org>
In-reply-to
Content
The attached _PyList_AppendTakeRef.diff has the ceval.c, but this implementation:

int
_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
{
    assert(self != NULL && newitem != NULL);
    assert(PyList_Check(self));
    Py_ssize_t len = PyList_GET_SIZE(self);
    Py_ssize_t allocated = self->allocated;
    assert((size_t)len + 1 < PY_SSIZE_T_MAX);
    if (allocated > len) {
        PyList_SET_ITEM(self, len, newitem);
        Py_SET_SIZE(self, len + 1);
        return 0;
    }
    if (list_resize(self, len + 1) < 0) {
        Py_DECREF(newitem);
        return -1;
    }
    PyList_SET_ITEM(self, len, newitem);
    return 0;
}

Results:

| Benchmark       | main              | PR 31864              | _PyList_AppendTakeRef.diff |
|-----------------|:-----------------:|:---------------------:|:--------------------------:|
| listcomp 100    | 1.61 us           | 1.33 us: 1.21x faster | 1.55 us: 1.04x faster      |
| append 100      | 2.11 us           | 1.82 us: 1.15x faster | 2.05 us: 1.03x faster      |
| listcomp 1000   | 12.6 us           | 9.83 us: 1.28x faster | 11.9 us: 1.06x faster      |
| append 1000     | 18.1 us           | 15.3 us: 1.18x faster | 17.6 us: 1.03x faster      |
| listcomp 10000  | 121 us            | 93.2 us: 1.29x faster | 114 us: 1.06x faster       |
| append 10000    | 175 us            | 150 us: 1.17x faster  | 172 us: 1.02x faster       |
| listcomp 100000 | 1.17 ms           | 923 us: 1.26x faster  | 1.15 ms: 1.02x faster      |
| append 100000   | 1.70 ms           | 1.49 ms: 1.14x faster | not significant            |
| Geometric mean  | (ref)             | 1.21x faster          | 1.03x faster               |
History
Date User Action Args
2022-03-14 10:35:39Dennis Sweeneysetrecipients: + Dennis Sweeney, methane
2022-03-14 10:35:39Dennis Sweeneysetmessageid: <1647254139.91.0.09798128077.issue47009@roundup.psfhosted.org>
2022-03-14 10:35:39Dennis Sweeneylinkissue47009 messages
2022-03-14 10:35:39Dennis Sweeneycreate