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.

classification
Title: Bypass unnecessary size limit test from deques on builds with 64-bit numbers
Type: performance Stage: patch review
Components: Extension Modules Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-10-15 15:36 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
deque_limit_test.diff rhettinger, 2015-10-15 16:04 review
deque_limit_remove.diff rhettinger, 2015-10-16 06:21 review
Messages (3)
msg253053 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-10-15 15:36
The following test can never succeed when PY_SSIZE_T_MAX is 63-bits (as that number of allocations would exceed possible time and memory).

    #define MAX_DEQUE_LEN (PY_SSIZE_T_MAX - 3*BLOCKLEN)

    if (len >= MAX_DEQUE_LEN) {
        PyErr_SetString(PyExc_OverflowError,
                        "cannot add more blocks to the deque");
        return NULL;
    }

Removing the test saves a recurring block of code through-out the module.  The block adds register pressure, triggers an unnecessary memory access and has a predictable test-and-jump.

Conditional compilation can leave the test in for builds with size_t under 64-bits.
msg253060 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-10-15 18:07
We can remove this test at all, it can never succeed on 32-bit platform. deque takes at least 4 bytes (PyObject*) per element. In 32-bit address space the maximal deque size is less than 2**32/4 = 2**30 that is much less than MAX_DEQUE_LEN = 2**31-1-3*64.
msg253121 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-10-17 05:47
New changeset 1733b3bd46db by Raymond Hettinger in branch 'default':
Issue #25414: Remove unnecessary tests that can never succeed.
https://hg.python.org/cpython/rev/1733b3bd46db
History
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69600
2015-10-17 06:57:44rhettingersetstatus: open -> closed
resolution: fixed
2015-10-17 05:47:37python-devsetnosy: + python-dev
messages: + msg253121
2015-10-16 06:21:11rhettingersetfiles: + deque_limit_remove.diff
2015-10-15 18:07:35serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg253060
2015-10-15 16:04:26rhettingersetfiles: - deque_limit_test.diff
2015-10-15 16:04:14rhettingersetfiles: + deque_limit_test.diff
2015-10-15 16:01:53rhettingersetfiles: + deque_limit_test.diff
title: Drop unnecessary size limit test from deques on builds with 64-bit numbers -> Bypass unnecessary size limit test from deques on builds with 64-bit numbers
components: + Extension Modules
keywords: + patch
type: performance
stage: patch review
2015-10-15 15:36:16rhettingercreate