This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author MrMrRobat
Recipients MrMrRobat
Date 2019-12-20.02:48:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:
  - All values/names access going through DynamicClassAttribute (x10 slower than accessing attr directly)
  - EnumMeta has __getattr__ which is slowing down even direct class attributes access (up to x6 slower)

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:
It's also related, because new Flag creation involves many lookups

My proposal:
  - I think we should completely get rid of __getattr__ on Enum (~6x speed boost)
  - Rework DynamicClassAttribute so it could work without __getattr__ or perhaps completely get rid of it
  - Don't use DynamicClassAttribute for and .value (~10x speed boost)
  - Think of faster handling of _missing_ hook  (~2x speed boost)
  - Make other improvements to the code

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.
Date User Action Args
2019-12-20 02:48:28MrMrRobatsetrecipients: + MrMrRobat
2019-12-20 02:48:28MrMrRobatsetmessageid: <>
2019-12-20 02:48:28MrMrRobatlinkissue39102 messages
2019-12-20 02:48:28MrMrRobatcreate