Skip to content
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 @@ -10,6 +10,9 @@ Changelog

version 1.8.1-dev
-----------------
+ Speed up ``import isal.igzip`` and ``import isal.igzip_threaded`` by
importing ``argparse`` and ``shutil`` only when the command line interface
runs, and by dropping the ``multiprocessing`` import.
+ Updated ISA-L to 2.32.1.
+ Python 3.10 and PyPy 3.10 are no longer supported. Added support for PyPy
3.12 and Python 3.15.
Expand Down
4 changes: 2 additions & 2 deletions src/isal/igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
"""Similar to the stdlib gzip module. But using the Intel Storage Accelaration
Library to speed up its methods."""

import argparse
import builtins
import gzip
import io
import os
import shutil
import struct
import sys
import time
Expand Down Expand Up @@ -255,6 +253,7 @@ def decompress(data):


def _argument_parser():
import argparse # Only the command line interface needs it
parser = argparse.ArgumentParser()
parser.description = (
"A simple command line interface for the igzip module. "
Expand Down Expand Up @@ -302,6 +301,7 @@ def _argument_parser():


def main():
import shutil # Only the command line interface needs it
args = _argument_parser().parse_args()

compresslevel = args.compresslevel or _COMPRESS_LEVEL_TRADEOFF
Expand Down
6 changes: 1 addition & 5 deletions src/isal/igzip_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import builtins
import io
import multiprocessing
import os
import queue
import struct
Expand Down Expand Up @@ -52,10 +51,7 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF,
try:
threads = len(os.sched_getaffinity(0))
except: # noqa: E722
try:
threads = multiprocessing.cpu_count()
except: # noqa: E722
threads = 1
threads = os.cpu_count() or 1
if "r" in mode:
gzip_file = io.BufferedReader(
_ThreadedGzipReader(filename, block_size=block_size))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import re
import shutil
import struct
import subprocess
import sys
import tempfile
import zlib
Expand Down Expand Up @@ -261,6 +262,18 @@ def test_compress_infile_out_file_no_name(tmp_path, capsysbinary):
assert output[4:8] == b"\x00\x00\x00\x00" # No timestamp set.


def test_import_does_not_load_cli_modules():
# Each of these modules takes milliseconds to import
code = ("import sys; before = set(sys.modules); "
"import isal.igzip, isal.igzip_threaded; "
"print(*(set(sys.modules) - before))")
result = subprocess.run([sys.executable, "-c", code], check=True,
capture_output=True, text=True)
new_modules = set(result.stdout.split())
assert "isal.igzip_threaded" in new_modules
assert not new_modules & {"argparse", "shutil", "multiprocessing"}


def test_decompress():
assert igzip.decompress(COMPRESSED_DATA) == DATA

Expand Down
Loading