-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Increase Enum performance #83283
Comments
Now enum has very poor speed on trying values and attributes access (especially when it comes to accessing members name/value attrs) There are two major reasons why attrs access is slow:
However, there are no need to use it, as we could just set value and name to newly created enum members without affecting its class. The main issue with values check is the slow _missing_ hook handling when it raising exception, which happens pretty much always, if value is not valid enum and we talking about vanilla Enum class. Also I found Flag performance issue being fixed already: My proposal:
Proposed changes doesn't require changing public API or behaviour. By far I were able to implement almost things proposed here and will be happy to make a PR. |
Also, do we need to leave compatibility with python <3.8? And another thing to think about: maybe we can calculate values returned by __str__, __repr__ and __invert__ once on member creation, since they not supposed to change during its life? For example __invert__ on Flag does a lot of work on every call: |
CC @mdboom . |
I believe this issue is no longer relevant as the ideas have been incorporated in other PRs; I'll double check at some point. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: