You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inline the per-item equality check in list.__contains__/index/count/remove #159092
list.__contains__(), index(), count(), remove(), and element comparisons in list.__eq__() use PyObject_RichCompareBool() for each element.
During a scan, the search value is fixed. Since we already know its type and its value, when an element has the same exact built-in type (int, float, or str), its comparison implementation is already known. Going through generic rich-comparison dispatch adds unnecessary type-dispatch and slot-handling overhead.
Add a fast path for these exact-type pairs, fall back to PyObject_RichCompareBool() for other cases.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
changed the title [-]Inline the per-item equality check in list.__contains__/index/count/remove[/-][+]Inline the per-item equality check in `list.__contains__/index/count/remove`[/+]on Oct 10, 2026
Activity
pythongh-159092: Optimize comparisons in list operations
pythongh-159092: Optimize comparisons in list operations
[-]Inline the per-item equality check in list.__contains__/index/count/remove[/-][+]Inline the per-item equality check in `list.__contains__/index/count/remove`[/+]corona10 commentedon Oct 10, 2026
My two cent is that if this workload is important this should be part of specializer rather than each implementation.
pythongh-159092: Optimize comparisons in list operations
pythongh-159092: Check inlined list comparisons in debug builds
pythongh-159092: Limit the list comparison fast path to list.__contai…