Skip to content

Optimize set and frozenset membership lookup (x in s) performance #153198

Description

@rajat315315

Feature or enhancement

Proposal:

Category

Performance

Description

Currently, set membership testing (x in s) via _PySet_Contains suffers from two performance bottlenecks:

  1. Indirect Function Pointer Calls in Probing Loop:
    The table probing function set_do_lookup in Objects/setobject.c receives the comparison function (compare_entry) as a function pointer argument:
    static int
    set_do_lookup(PySetObject *so, setentry *table, size_t mask, PyObject *key,
                  Py_hash_t hash, setentry **epp, compare_func compare_entry)
    

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions