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

python -m gzip could use a larger buffer #87483

Closed
rhpvorderman mannequin opened this issue Feb 24, 2021 · 2 comments
Closed

python -m gzip could use a larger buffer #87483

rhpvorderman mannequin opened this issue Feb 24, 2021 · 2 comments
Labels
3.10 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@rhpvorderman
Copy link
Mannequin

rhpvorderman mannequin commented Feb 24, 2021

BPO 43317
Nosy @tirkarthi, @rhpvorderman
PRs
  • bpo-43317: Use io.DEFAULT_BUFFER_SIZE instead of arbitrary number in gzip module #24645
  • 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 2021-02-26.12:18:14.135>
    created_at = <Date 2021-02-24.15:06:00.113>
    labels = ['library', '3.10', 'performance']
    title = 'python -m gzip could use a larger buffer'
    updated_at = <Date 2021-02-26.12:18:14.133>
    user = 'https://github.com/rhpvorderman'

    bugs.python.org fields:

    activity = <Date 2021-02-26.12:18:14.133>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-02-26.12:18:14.135>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2021-02-24.15:06:00.113>
    creator = 'rhpvorderman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43317
    keywords = ['patch']
    message_count = 2.0
    messages = ['387624', '387722']
    nosy_count = 2.0
    nosy_names = ['xtreak', 'rhpvorderman']
    pr_nums = ['24645']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue43317'
    versions = ['Python 3.10']

    @rhpvorderman
    Copy link
    Mannequin Author

    rhpvorderman mannequin commented Feb 24, 2021

    python -m gzip reads in chunks of 1024 bytes:

    chunk = f.read(1024)

    This hurts performance somewhat. Using io.DEFAULT_BUFFER_SIZE will improve it. Also 'io.DEFAULT_BUFFER_SIZE' is better than: 'ARBITRARY_NUMBER_WITH_NO_COMMENT_EXPLAINING_WHY'.

    With 1024 blocks
    Decompression:
    $ hyperfine -r 10 -w 3 'cat ~/test/500000reads.fastq.gz | ./prefix/bin/python3 -m gzip -d > /dev/null'
    Benchmark #1: cat ~/test/500000reads.fastq.gz | ./prefix/bin/python3 -m gzip -d > /dev/null
    Time (mean ± σ): 926.9 ms ± 7.7 ms [User: 901.2 ms, System: 59.1 ms]
    Range (min … max): 913.3 ms … 939.4 ms 10 runs

    Compression:
    $ hyperfine -r 10 -w 3 'cat ~/test/500000reads.fastq | ./prefix/bin/python3 -m gzip --fast > /dev/null'
    Benchmark #1: cat ~/test/500000reads.fastq | ./prefix/bin/python3 -m gzip --fast > /dev/null
    Time (mean ± σ): 2.514 s ± 0.030 s [User: 2.469 s, System: 0.125 s]
    Range (min … max): 2.472 s … 2.563 s 10 runs

    with io.DEFAULT_BUFFER_SIZE
    Decompression:
    $ hyperfine -r 10 -w 3 'cat ~/test/500000reads.fastq.gz | ./prefix/bin/python3 -m gzip -d > /dev/null'
    Benchmark #1: cat ~/test/500000reads.fastq.gz | ./prefix/bin/python3 -m gzip -d > /dev/null
      Time (mean ± σ):     839.9 ms ±   7.3 ms    [User: 816.0 ms, System: 57.3 ms]
      Range (minmax):   830.1 ms851.3 ms    10 runs

    Compression:
    $ hyperfine -r 10 -w 3 'cat ~/test/500000reads.fastq | ./prefix/bin/python3 -m gzip --fast > /dev/null'
    Benchmark #1: cat ~/test/500000reads.fastq | ./prefix/bin/python3 -m gzip --fast > /dev/null
    Time (mean ± σ): 2.275 s ± 0.024 s [User: 2.247 s, System: 0.096 s]
    Range (min … max): 2.254 s … 2.322 s 10 runs

    Speedups:

    • Decompression 840 / 927 = 0.906 ~= 9% reduction in runtime
    • Compression 2.275 / 2.514 = 0.905 ~= 9% reduction in runtime.

    It is not stellar, but it is a quite nice improvement for such a tiny change.

    @rhpvorderman rhpvorderman mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir performance Performance or resource usage labels Feb 24, 2021
    @methane
    Copy link
    Member

    methane commented Feb 26, 2021

    New changeset 7956ef8 by Ruben Vorderman in branch 'master':
    bpo-43317: Use io.DEFAULT_BUFFER_SIZE instead of 1024 in gzip CLI (bpo-24645)
    7956ef8

    @methane methane removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Feb 26, 2021
    @methane methane closed this as completed Feb 26, 2021
    @methane methane removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Feb 26, 2021
    @methane methane closed this as completed Feb 26, 2021
    @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.10 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant