Skip to content

Inline the per-item equality check in list.__contains__/index/count/remove #159092

Description

@hetaozdh

Feature or enhancement

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

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added 2 commits that reference this issue on Oct 9, 2026
  2. 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
  3. corona10 commented on Oct 10, 2026

    @corona10
    Member

    My two cent is that if this workload is important this should be part of specializer rather than each implementation.

  4. added a commit that references this issue on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions