Skip to content

Commit eece4fc

Browse files
committed
Slightly increase buffer size in the CLI application for 6% speed improvement
1 parent f688a15 commit eece4fc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/isal/igzip.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import os
2828
import sys
2929

30-
import _compression
31-
3230
from . import isal_zlib
3331

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

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

283285
compresslevel = args.compresslevel or _COMPRESS_LEVEL_TRADEOFF
@@ -310,7 +312,7 @@ def main():
310312

311313
try:
312314
while True:
313-
block = in_file.read(BUFFER_SIZE)
315+
block = in_file.read(args.buffer_size)
314316
if block == b"":
315317
break
316318
out_file.write(block)

0 commit comments

Comments
 (0)