[New-bugs-announce] [issue43787] Optimize BZ2File, GzipFile, and LZMAFile __iter__ method.
Inada Naoki
report at bugs.python.org
Fri Apr 9 04:49:43 EDT 2021
New submission from Inada Naoki <songofacandy at gmail.com>:
__iter__ method of BZ2File, GzipFile, and LZMAFile is IOBase.__iter__. It calls `readline()` for each line.
Since `readline()` is defined as Python function, it is slower than C iterator. Adding custom __iter__ method that delegates to underlying buffer __iter__ makes `for line in file` 2x faster.
def __iter__(self):
self._check_can_read()
return self._buffer.__iter__()
---
The original issue is reported here.
https://discuss.python.org/t/non-optimal-bz2-reading-speed/6869
This issue is relating to #43785.
----------
components: Library (Lib)
messages: 390599
nosy: methane
priority: normal
severity: normal
status: open
title: Optimize BZ2File, GzipFile, and LZMAFile __iter__ method.
type: performance
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43787>
_______________________________________
More information about the New-bugs-announce
mailing list