[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-06-01 Thread Dale Visser
Dale Visser added the comment: I've learned a lot about the performance trade-offs of generator expressions. The only way of shortening this code (readability is subjective) that I've found not to negatively impact performance is this: def filter(self, record): rv = True

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-31 Thread Dale Visser
Dale Visser added the comment: FWIW, when I tried this instead, I got 21 to 22 msec per 1000 log messages (still a 5-10% performance hit): def filter(self, record): rv = True if self.filters: rv = all(getattr(f, 'filter', f)(record) for f in self.filters) return rv I

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-31 Thread Dale Visser
Dale Visser added the comment: Adding the patch file associated with GitHub pull request #13683, as well as the performance test I just reported. -- Added file: https://bugs.python.org/file48383/pr13683.diff ___ Python tracker <ht

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-31 Thread Dale Visser
Dale Visser added the comment: Correction on that example of running the test script: ./python test_filter_perf.py all 100 I simply prepended this with the Linux `time` command for measuring. -- ___ Python tracker <https://bugs.python.

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-31 Thread Dale Visser
Dale Visser added the comment: It is with great surprise and sadness that I report that I found that performance measurements don't support merging this change. I'm attaching my performance test script. I ran it with/without the logging filters for 100 iterations, e.g., ./python all

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-30 Thread Dale Visser
Dale Visser added the comment: Great! My PR now uses getattr as @zach.ware has suggested. -- ___ Python tracker <https://bugs.python.org/issue37101> ___ ___

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-30 Thread Dale Visser
Change by Dale Visser : -- keywords: +patch pull_requests: +13570 stage: -> patch review pull_request: https://github.com/python/cpython/pull/13683 ___ Python tracker <https://bugs.python.org/issu

[issue37101] Filterer.filter can be rewritten using built-ins just as efficient much more readable

2019-05-30 Thread Dale Visser
New submission from Dale Visser : Alternative version of Filterer.filter(...) would look like this, which takes advantage of efficient Python 3.x built-ins, and is immediately understandable: def _filter_callable(filter): return filter.filter if hasattr(filter, 'filter') else filter def