Skip to content

Improve performance of membership checks in registry #20671

@allrob23

Description

@allrob23

Outline & Motivation

The available_accelerators method currently returns a list, but using a set is a better choice for performance reasons. Since the method is mainly used for membership checks (in operations), sets offer O(1) average-time complexity compared to lists' O(n).

Proposed Change:
Modify available_accelerators to return a set instead of a list:

def available_accelerators(self) -> set[str]:  
    """Returns a set of registered accelerators."""  
    return set(self.keys())

Benefits:

  • Faster membership checks (like accelerator not in self._accelerator_types -- in accelerator_connectior.py) instead of O(n))
  • Improves efficiency when handling a large number of accelerators

Would love to hear thoughts from the maintainers on this! 🚀

Pitch

No response

Additional context

No response

cc @lantiga @justusschock

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions