Skip to content

Document that enums with unhashable members are created non-performantly #105535

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

Closed
mzhu22 opened this issue Jun 8, 2023 · 4 comments
Closed
Labels
docs Documentation in the Doc dir

Comments

@mzhu22
Copy link

mzhu22 commented Jun 8, 2023

Documentation

#28907 fixes enum creation taking quadratic time relative to the number of members, but only for members whose values are hashable. If not fixed, ideally this would be documented somewhere as it could potentially be a big performance trap

Linked PRs

@mzhu22 mzhu22 added the docs Documentation in the Doc dir label Jun 8, 2023
@nicky-eng
Copy link
Contributor

I will try to create a pull request for this issue. I think it will be done by the end of the day.

@ethanfurman
Copy link
Member

@mzhu22: Out of curiosity, do you have an actual use-case that uses many unhashable values?

@mzhu22
Copy link
Author

mzhu22 commented Jul 24, 2023

@ethanfurman So not a use-case of unhashable values, but rather an example of the performance trap.

We have a use-case of dynamically generating Enums from user data. Originally the enum member values were strings, but we switched to dataclasses to include additional metadata. For some corner cases where enums had a lot of values, we noticed a dramatic performance hit, until we looked into it, and made the dataclasses immutable.

@ethanfurman
Copy link
Member

Definitely a good reason for the warning.

ethanfurman added a commit that referenced this issue Mar 8, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 8, 2024
…ion (pythonGH-107119)

(cherry picked from commit 601f3a7)

Co-authored-by: Nicolas A. Oyarzabal <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 8, 2024
…ion (pythonGH-107119)

(cherry picked from commit 601f3a7)

Co-authored-by: Nicolas A. Oyarzabal <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
ethanfurman added a commit that referenced this issue Mar 9, 2024
…tion (GH-107119) (GH116511)

(cherry picked from commit 601f3a7)

Co-authored-by: Nicolas A. Oyarzabal <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
ethanfurman added a commit that referenced this issue Mar 9, 2024
…tion (GH-107119) (GH-116512)

(cherry picked from commit 601f3a7)

Co-authored-by: Nicolas A. Oyarzabal <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants