Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of membership checks in registry #20671

Closed
allrob23 opened this issue Mar 25, 2025 · 0 comments · Fixed by #20672
Closed

Improve performance of membership checks in registry #20671

allrob23 opened this issue Mar 25, 2025 · 0 comments · Fixed by #20672
Labels
needs triage Waiting to be triaged by maintainers refactor

Comments

@allrob23
Copy link
Contributor

allrob23 commented Mar 25, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Waiting to be triaged by maintainers refactor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant