Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize textio write buffering #80929

Closed
methane opened this issue Apr 29, 2019 · 2 comments
Closed

Optimize textio write buffering #80929

methane opened this issue Apr 29, 2019 · 2 comments
Labels
3.8 (EOL) end of life performance Performance or resource usage topic-IO

Comments

@methane
Copy link
Member

methane commented Apr 29, 2019

BPO 36748
Nosy @methane
PRs
  • bpo-36748: optimize TextIOWrapper.write() for ASCII string #13002
  • bpo-36927: Improve the docstring and Doc of traceback. #13359
  • Files
  • bm_textio.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-16.06:20:43.711>
    created_at = <Date 2019-04-29.06:12:38.657>
    labels = ['3.8', 'expert-IO', 'performance']
    title = 'Optimize textio write buffering'
    updated_at = <Date 2019-05-16.19:34:02.847>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2019-05-16.19:34:02.847>
    actor = 'mangrisano'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-16.06:20:43.711>
    closer = 'methane'
    components = ['IO']
    creation = <Date 2019-04-29.06:12:38.657>
    creator = 'methane'
    dependencies = []
    files = ['48289']
    hgrepos = []
    issue_num = 36748
    keywords = ['patch']
    message_count = 2.0
    messages = ['341044', '342627']
    nosy_count = 1.0
    nosy_names = ['methane']
    pr_nums = ['13002', '13359']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue36748'
    versions = ['Python 3.8']

    @methane
    Copy link
    Member Author

    methane commented Apr 29, 2019

    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%)

    @methane methane added 3.8 (EOL) end of life topic-IO performance Performance or resource usage labels Apr 29, 2019
    @methane
    Copy link
    Member Author

    methane commented May 16, 2019

    New changeset bfba8c3 by Inada Naoki in branch 'master':
    bpo-36748: optimize TextIOWrapper.write() for ASCII string (GH-13002)
    bfba8c3

    @methane methane closed this as completed May 16, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life performance Performance or resource usage topic-IO
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant