#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
@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.
Activity
nicky-eng commented on Jul 23, 2023
I will try to create a pull request for this issue. I think it will be done by the end of the day.
pythongh-105535 Document potential performance trap during enum creation
pythongh-105535: Add warning about quadratical growth
ethanfurman commented on Jul 24, 2023
@mzhu22: Out of curiosity, do you have an actual use-case that uses many unhashable values?
mzhu22 commented on 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 commented on Jul 24, 2023
Definitely a good reason for the warning.
gh-105535 Document potential performance trap during enum creation (G…
pythongh-105535 Document potential performance trap during enum creat…
pythongh-105535 Document potential performance trap during enum creat…
[3.12] gh-105535 Document potential performance trap during enum crea…
[3.11] gh-105535 Document potential performance trap during enum crea…
pythongh-105535 Document potential performance trap during enum creat…
pythongh-105535 Document potential performance trap during enum creat…