You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enum creation is quadratic in the number of members (_hashable_values_ list scan) #158856
Creating an Enum is quadratic in the number of members again. When each member is added, _proto_member.__set_name__ runs value not in enum_class._hashable_values_, and _hashable_values_ is a list, so every new member scans all the ones before it.
On main (3.16 dev, macOS arm64): 5.8 / 54 / 187 / 713 ms. Each doubling of n costs about 4x.
This is the same symptom as gh-89580, which was fixed. The _hashable_values_ scan came in later.
The scan is only needed when the value was already in _value2member_map_ before this member was added, for example an alias or a Flag pseudo-member that the class cached earlier. If setdefault just added the key, the value can't be in the list yet.
Activity
gh-158856: convert `Enum._hashable_values_` to a set (GH-159250)