Skip to content

Bigger buffer for the Command Line interface. #39

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

Merged
merged 2 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changelog

version 0.5.0-dev
-----------------
+ The command-line interface now reads in blocks of 32K instead of 8K. This
improves performance by about 6% when compressing and 11% when decompressing.
A hidden ``-b`` flag was added to adjust the buffer size for benchmarks.
+ A ``-c`` or ``--stdout`` flag was added to the CLI interface of isal.igzip.
This allows it to behave more like the ``gzip`` or ``pigz`` command line
interfaces.
Expand Down
12 changes: 7 additions & 5 deletions src/isal/igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import os
import sys

import _compression

from . import isal_zlib

__all__ = ["IGzipFile", "open", "compress", "decompress", "BadGzipFile"]
Expand All @@ -37,8 +35,6 @@
_COMPRESS_LEVEL_TRADEOFF = isal_zlib.ISAL_DEFAULT_COMPRESSION
_COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION

BUFFER_SIZE = _compression.BUFFER_SIZE

try:
BadGzipFile = gzip.BadGzipFile
except AttributeError: # Versions lower than 3.8 do not have BadGzipFile
Expand Down Expand Up @@ -278,6 +274,12 @@ def main():
help="Decompress the file instead of compressing.")
parser.add_argument("-c", "--stdout", action="store_true",
help="write on standard output")
# -b flag not taken by either gzip or igzip. Hidden attribute. Above 32K
# diminishing returns hit. _compression.BUFFER_SIZE = 8k. But 32K is about
# ~6% faster.
parser.add_argument("-b", "--buffer-size",
default=32 * 1024, type=int,
help=argparse.SUPPRESS)
args = parser.parse_args()

compresslevel = args.compresslevel or _COMPRESS_LEVEL_TRADEOFF
Expand Down Expand Up @@ -310,7 +312,7 @@ def main():

try:
while True:
block = in_file.read(BUFFER_SIZE)
block = in_file.read(args.buffer_size)
if block == b"":
break
out_file.write(block)
Expand Down