[issue39102] Increase Enum performance

2021-04-11 Thread Ethan Furman


Change by Ethan Furman :


--
stage: patch review -> needs patch
versions: +Python 3.10 -Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2020-08-30 Thread jack1142


Change by jack1142 :


--
nosy: +jack1142

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2020-08-09 Thread Inada Naoki


Change by Inada Naoki :


--
nosy: +inada.naoki

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2020-08-08 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy:  -pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-26 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-20 Thread Arseny Boykov


Arseny Boykov  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-20 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions:  -Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-20 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


--
nosy: +levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +barry, eli.bendersky, ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


Change by Arseny Boykov :


--
keywords: +patch
pull_requests: +17133
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17669

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


New submission from Arseny Boykov :

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:
https://bugs.python.org/issue38045
It's also related, because new Flag creation involves many member.name 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 member.name 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.

--
components: Library (Lib)
files: benchmark_result.txt
messages: 358694
nosy: MrMrRobat
priority: normal
severity: normal
status: open
title: Increase Enum performance
type: performance
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48793/benchmark_result.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com