New submission from Inada Naoki <songofaca...@gmail.com>:

textio uses list of textio for internal buffering.  There are two inefficiency:

* When textio is line buffered and all written strings are line (it's very 
common), list object is allocated and freed.
* We convert texts into bytes, and call b''.join(list_of_bytes).  But when 
texts are ASCII and codecs are ASCII-compat, we can skip temporary bytes 
objects.

Attached patch is benchmark for buffered and line buffered write.

Faster (6):
- write_ascii_32k: 101 ns +- 1 ns -> 73.1 ns +- 0.4 ns: 1.39x faster (-28%)
- write_ascii_8k: 102 ns +- 1 ns -> 73.4 ns +- 0.4 ns: 1.38x faster (-28%)
- write_ascii_linebuffered: 815 ns +- 12 ns -> 731 ns +- 3 ns: 1.12x faster 
(-10%)
- write_unicode_linebuffered: 840 ns +- 11 ns -> 789 ns +- 15 ns: 1.06x faster 
(-6%)
- write_unicode_8k: 124 ns +- 1 ns -> 122 ns +- 1 ns: 1.01x faster (-1%)
- write_unicode_32k: 124 ns +- 1 ns -> 122 ns +- 1 ns: 1.01x faster (-1%)

----------
components: IO
files: bm_textio.py
messages: 341044
nosy: inada.naoki
priority: normal
severity: normal
status: open
title: Optimize textio write buffering
type: performance
versions: Python 3.8
Added file: https://bugs.python.org/file48289/bm_textio.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36748>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to