Mercurial > public > mercurial-scm > hg
comparison contrib/python-zstandard/c-ext/compressor.c @ 30895:c32454d69b85
zstd: vendor python-zstandard 0.7.0
Commit 3054ae3a66112970a091d3939fee32c2d0c1a23e from
https://github.com/indygreg/python-zstandard is imported without
modifications (other than removing unwanted files).
The vendored zstd library within has been upgraded from 1.1.2 to
1.1.3. This version introduced new APIs for threads, thread
pools, multi-threaded compression, and a new dictionary
builder (COVER). These features are not yet used by
python-zstandard (or Mercurial for that matter). However,
that will likely change in the next python-zstandard release
(and I think there are opportunities for Mercurial to take
advantage of the multi-threaded APIs).
Relevant to Mercurial, the CFFI bindings are now fully
implemented. This means zstd should "just work" with PyPy
(although I haven't tried). The python-zstandard test suite also
runs all tests against both the C extension and CFFI bindings to
ensure feature parity.
There is also a "decompress_content_dict_chain()" API. This was
derived from discussions with Yann Collet on list about alternate
ways of encoding delta chains.
The change most relevant to Mercurial is a performance enhancement in
the simple decompression API to reuse a data structure across
operations. This makes decompression of multiple inputs significantly
faster. (This scenario occurs when reading revlog delta chains, for
example.)
Using python-zstandard's bench.py to measure the performance
difference...
On changelog chunks in the mozilla-unified repo:
decompress discrete decompress() reuse zctx
1.262243 wall; 1.260000 CPU; 1.260000 user; 0.000000 sys 170.43 MB/s (best of 3)
0.949106 wall; 0.950000 CPU; 0.950000 user; 0.000000 sys 226.66 MB/s (best of 4)
decompress discrete dict decompress() reuse zctx
0.692170 wall; 0.690000 CPU; 0.690000 user; 0.000000 sys 310.80 MB/s (best of 5)
0.437088 wall; 0.440000 CPU; 0.440000 user; 0.000000 sys 492.17 MB/s (best of 7)
On manifest chunks in the mozilla-unified repo:
decompress discrete decompress() reuse zctx
1.367284 wall; 1.370000 CPU; 1.370000 user; 0.000000 sys 274.01 MB/s (best of 3)
1.086831 wall; 1.080000 CPU; 1.080000 user; 0.000000 sys 344.72 MB/s (best of 3)
decompress discrete dict decompress() reuse zctx
0.993272 wall; 0.990000 CPU; 0.990000 user; 0.000000 sys 377.19 MB/s (best of 3)
0.678651 wall; 0.680000 CPU; 0.680000 user; 0.000000 sys 552.06 MB/s (best of 5)
That should make reads on zstd revlogs a bit faster ;)
# no-check-commit
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 07 Feb 2017 23:24:47 -0800 |
parents | 08fa3a76a080 |
children | e0dc40530c5a |
comparison
equal
deleted
inserted
replaced
30894:5b60464efbde | 30895:c32454d69b85 |
---|---|
14 ZSTD_customMem zmem; | 14 ZSTD_customMem zmem; |
15 assert(!compressor->cdict); | 15 assert(!compressor->cdict); |
16 Py_BEGIN_ALLOW_THREADS | 16 Py_BEGIN_ALLOW_THREADS |
17 memset(&zmem, 0, sizeof(zmem)); | 17 memset(&zmem, 0, sizeof(zmem)); |
18 compressor->cdict = ZSTD_createCDict_advanced(compressor->dict->dictData, | 18 compressor->cdict = ZSTD_createCDict_advanced(compressor->dict->dictData, |
19 compressor->dict->dictSize, *zparams, zmem); | 19 compressor->dict->dictSize, 1, *zparams, zmem); |
20 Py_END_ALLOW_THREADS | 20 Py_END_ALLOW_THREADS |
21 | 21 |
22 if (!compressor->cdict) { | 22 if (!compressor->cdict) { |
23 PyErr_SetString(ZstdError, "could not create compression dictionary"); | 23 PyErr_SetString(ZstdError, "could not create compression dictionary"); |
24 return 1; | 24 return 1; |
126 self->cctx = NULL; | 126 self->cctx = NULL; |
127 self->dict = NULL; | 127 self->dict = NULL; |
128 self->cparams = NULL; | 128 self->cparams = NULL; |
129 self->cdict = NULL; | 129 self->cdict = NULL; |
130 | 130 |
131 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO!O!OOO", kwlist, | 131 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO!O!OOO:ZstdCompressor", |
132 &level, &ZstdCompressionDictType, &dict, | 132 kwlist, &level, &ZstdCompressionDictType, &dict, |
133 &CompressionParametersType, ¶ms, | 133 &CompressionParametersType, ¶ms, |
134 &writeChecksum, &writeContentSize, &writeDictID)) { | 134 &writeChecksum, &writeContentSize, &writeDictID)) { |
135 return -1; | 135 return -1; |
136 } | 136 } |
137 | 137 |
241 size_t zresult; | 241 size_t zresult; |
242 PyObject* writeResult; | 242 PyObject* writeResult; |
243 PyObject* totalReadPy; | 243 PyObject* totalReadPy; |
244 PyObject* totalWritePy; | 244 PyObject* totalWritePy; |
245 | 245 |
246 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|nkk", kwlist, &source, &dest, &sourceSize, | 246 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|nkk:copy_stream", kwlist, |
247 &inSize, &outSize)) { | 247 &source, &dest, &sourceSize, &inSize, &outSize)) { |
248 return NULL; | 248 return NULL; |
249 } | 249 } |
250 | 250 |
251 if (!PyObject_HasAttrString(source, "read")) { | 251 if (!PyObject_HasAttrString(source, "read")) { |
252 PyErr_SetString(PyExc_ValueError, "first argument must have a read() method"); | 252 PyErr_SetString(PyExc_ValueError, "first argument must have a read() method"); |
400 size_t dictSize = 0; | 400 size_t dictSize = 0; |
401 size_t zresult; | 401 size_t zresult; |
402 ZSTD_parameters zparams; | 402 ZSTD_parameters zparams; |
403 | 403 |
404 #if PY_MAJOR_VERSION >= 3 | 404 #if PY_MAJOR_VERSION >= 3 |
405 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|O", | 405 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|O:compress", |
406 #else | 406 #else |
407 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O", | 407 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:compress", |
408 #endif | 408 #endif |
409 kwlist, &source, &sourceSize, &allowEmpty)) { | 409 kwlist, &source, &sourceSize, &allowEmpty)) { |
410 return NULL; | 410 return NULL; |
411 } | 411 } |
412 | 412 |
510 ZstdCompressionObj* result = PyObject_New(ZstdCompressionObj, &ZstdCompressionObjType); | 510 ZstdCompressionObj* result = PyObject_New(ZstdCompressionObj, &ZstdCompressionObjType); |
511 if (!result) { | 511 if (!result) { |
512 return NULL; | 512 return NULL; |
513 } | 513 } |
514 | 514 |
515 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|n", kwlist, &inSize)) { | 515 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|n:compressobj", kwlist, &inSize)) { |
516 return NULL; | 516 return NULL; |
517 } | 517 } |
518 | 518 |
519 result->cstream = CStream_from_ZstdCompressor(self, inSize); | 519 result->cstream = CStream_from_ZstdCompressor(self, inSize); |
520 if (!result->cstream) { | 520 if (!result->cstream) { |
572 Py_ssize_t sourceSize = 0; | 572 Py_ssize_t sourceSize = 0; |
573 size_t inSize = ZSTD_CStreamInSize(); | 573 size_t inSize = ZSTD_CStreamInSize(); |
574 size_t outSize = ZSTD_CStreamOutSize(); | 574 size_t outSize = ZSTD_CStreamOutSize(); |
575 ZstdCompressorIterator* result; | 575 ZstdCompressorIterator* result; |
576 | 576 |
577 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nkk", kwlist, &reader, &sourceSize, | 577 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nkk:read_from", kwlist, |
578 &inSize, &outSize)) { | 578 &reader, &sourceSize, &inSize, &outSize)) { |
579 return NULL; | 579 return NULL; |
580 } | 580 } |
581 | 581 |
582 result = PyObject_New(ZstdCompressorIterator, &ZstdCompressorIteratorType); | 582 result = PyObject_New(ZstdCompressorIterator, &ZstdCompressorIteratorType); |
583 if (!result) { | 583 if (!result) { |
691 PyObject* writer; | 691 PyObject* writer; |
692 ZstdCompressionWriter* result; | 692 ZstdCompressionWriter* result; |
693 Py_ssize_t sourceSize = 0; | 693 Py_ssize_t sourceSize = 0; |
694 size_t outSize = ZSTD_CStreamOutSize(); | 694 size_t outSize = ZSTD_CStreamOutSize(); |
695 | 695 |
696 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nk", kwlist, &writer, &sourceSize, | 696 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nk:write_to", kwlist, |
697 &outSize)) { | 697 &writer, &sourceSize, &outSize)) { |
698 return NULL; | 698 return NULL; |
699 } | 699 } |
700 | 700 |
701 if (!PyObject_HasAttrString(writer, "write")) { | 701 if (!PyObject_HasAttrString(writer, "write")) { |
702 PyErr_SetString(PyExc_ValueError, "must pass an object with a write() method"); | 702 PyErr_SetString(PyExc_ValueError, "must pass an object with a write() method"); |