-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Open
Labels
easyextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
queue.SimpleQueue
(C level) uses a list on Python < 3.13[1][2][3][4], a ring buffer on Python >= 3.13[5][6]. However, it does not implement its own __sizeof__()
method, and as a result, only the size of the simplequeueobject
structure itself (basicsize
) is taken as the size of the object, while the size of the underlying structure is ignored.
>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
72 # 56 on Python < 3.13
>>> for _ in range(1_000):
... q.put(object())
...
>>> q.__sizeof__()
72 # 56 on Python < 3.13
Expected (should be, on Python >= 3.13):
>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
136 # == 72 + 8*8 == sizeof(simplequeueobject) + sizeof(PyObject *)*INITIAL_RING_BUF_CAPACITY
>>> for _ in range(1_000):
... q.put(object())
...
>>> q.__sizeof__()
8264 # == 72 + 8*1024 == sizeof(simplequeueobject) + sizeof(PyObject *)*pow(2, ceil(log2(1000)))
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
serhiy-storchaka
Metadata
Metadata
Assignees
Labels
easyextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error