[issue39102] Increase Enum performance

Arseny Boykov report at bugs.python.org
Fri Dec 20 17:59:56 EST 2019


Arseny Boykov <appkiller16 at gmail.com> added the comment:

Also, do we need to leave compatibility with python <3.8? 
If not, we could use the fact that python 3.8 dicts and sets which are preserve order to speed things up even more. Also I'd replace % string formatting with f-strings, as they also faster.

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:
    def __invert__(self):
        cls = self.__class__
        members, uncovered = _decompose(cls, self._value_)
        inverted = cls(0)
        for m in cls:
            if m not in members and not (m._value_ & self._value_):
                inverted = inverted | m
        return cls(inverted)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39102>
_______________________________________


More information about the Python-bugs-list mailing list