Skip to content

Commit 7bea67b

Browse files
committed
Make input buffer configurable and find optimal size
1 parent 23e0500 commit 7bea67b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/isal/igzip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ def __init__(self, filename=None, mode=None,
167167
isal_zlib.DEF_MEM_LEVEL,
168168
0)
169169
if self.mode == READ:
170-
raw = _IGzipReader(self.fileobj)
171-
self._buffer = io.BufferedReader(raw, 64 * 1024)
170+
# Having a large input buffer seems to work well for both normal
171+
# gzip and BGZIP files.
172+
raw = _IGzipReader(self.fileobj, 512 * 1024)
173+
self._buffer = io.BufferedReader(raw)
172174

173175
def __repr__(self):
174176
s = repr(self.fileobj)

src/isal/isal_zlib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ def compressobj(level: int = ISAL_DEFAULT_COMPRESSION,
6666
def decompressobj(wbits: int = MAX_WBITS, zdict = None) -> Decompress: ...
6767

6868
class _IGzipReader(io.RawIOBase):
69-
def __init__(self, fp: typing.BinaryIO): ...
69+
def __init__(self, fp: typing.BinaryIO, buffersize: int = 32 * 1024): ...

src/isal/isal_zlibmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,10 +1273,11 @@ static PyObject *
12731273
IGzipReader__new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
12741274
{
12751275
PyObject *fp;
1276-
static char *keywords[] = {"fp", NULL};
1277-
static char *format = "O:IGzipReader";
1276+
Py_ssize_t buffer_size = 32 * 1024;
1277+
static char *keywords[] = {"fp", "buffersize", NULL};
1278+
static char *format = "O|n:IGzipReader";
12781279
if (!PyArg_ParseTupleAndKeywords(
1279-
args, kwargs, format, keywords, &fp)) {
1280+
args, kwargs, format, keywords, &fp, &buffer_size)) {
12801281
return NULL;
12811282
}
12821283
IGzipReader *self = PyObject_New(IGzipReader, type);
@@ -1296,7 +1297,7 @@ IGzipReader__new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
12961297
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
12971298
return NULL;
12981299
}
1299-
self->buffer_size = 32 * 1024;
1300+
self->buffer_size = buffer_size;
13001301
self->input_buffer = PyMem_Malloc(self->buffer_size);
13011302
if (self->input_buffer == NULL) {
13021303
Py_DECREF(self);

0 commit comments

Comments
 (0)