This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Inefficient
Type: performance Stage: resolved
Components: IO Versions: Python 3.10
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: malin
Priority: normal Keywords: patch

Created on 2020-08-01 03:34 by malin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit malin, 2020-08-01 03:34
Pull Requests
URL Status Linked Edit
PR 21698 closed malin, 2020-08-01 05:37
Messages (2)
msg374652 - (view) Author: Ma Lin (malin) * Date: 2020-08-01 03:34
BufferedReader's constructor has a `buffer_size` parameter, it's the size of this buffer:

    When reading data from BufferedReader object, a larger
    amount of data may be requested from the underlying raw
    stream, and kept in an internal buffer.
    The doc of BufferedReader[1]

If call the function:

    1, When `size` is a positive number, it reads `buffer_size`
       bytes from the underlying stream. This is expected behavior.

    2, When `size` is -1, it tries to call underlying stream's
       readall() function [2]. In this case `buffer_size` is not
       be respected.
       The underlying stream may be `RawIOBase`, its readall()
       function read `DEFAULT_BUFFER_SIZE` bytes in each read [3].
       `DEFAULT_BUFFER_SIZE` currently only 8KB, which is very
       inefficient for If `buffer_size`
       bytes is read every time, will be the expected performance.

Attached file demonstrates this problem.

[1] doc of BufferedReader:

[2] tries to call underlying stream's readall() function:

[3] RawIOBase.readall() read DEFAULT_BUFFER_SIZE each time:
msg374657 - (view) Author: Ma Lin (malin) * Date: 2020-08-01 05:59
Some underlying stream has fast-path for .readall().
So close this issue.
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85624
2020-08-01 05:59:43malinsetstatus: open -> closed

messages: + msg374657
stage: patch review -> resolved
2020-08-01 05:37:39malinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20842
2020-08-01 03:34:14malincreate