lzrans 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. lzrans-1.0.0/CHANGELOG.md +32 -0
  2. lzrans-1.0.0/LICENSE +21 -0
  3. lzrans-1.0.0/MANIFEST.in +4 -0
  4. lzrans-1.0.0/PKG-INFO +210 -0
  5. lzrans-1.0.0/README.md +183 -0
  6. lzrans-1.0.0/include/lzr.h +202 -0
  7. lzrans-1.0.0/lzrans/__init__.py +38 -0
  8. lzrans-1.0.0/lzrans.egg-info/PKG-INFO +210 -0
  9. lzrans-1.0.0/lzrans.egg-info/SOURCES.txt +38 -0
  10. lzrans-1.0.0/lzrans.egg-info/dependency_links.txt +1 -0
  11. lzrans-1.0.0/lzrans.egg-info/requires.txt +3 -0
  12. lzrans-1.0.0/lzrans.egg-info/top_level.txt +1 -0
  13. lzrans-1.0.0/pyproject.toml +51 -0
  14. lzrans-1.0.0/setup.cfg +4 -0
  15. lzrans-1.0.0/setup.py +54 -0
  16. lzrans-1.0.0/src/lzrans/api.c +403 -0
  17. lzrans-1.0.0/src/lzrans/arc.h +338 -0
  18. lzrans-1.0.0/src/lzrans/codes.h +87 -0
  19. lzrans-1.0.0/src/lzrans/common.h +132 -0
  20. lzrans-1.0.0/src/lzrans/core.h +163 -0
  21. lzrans-1.0.0/src/lzrans/crc32.c +43 -0
  22. lzrans-1.0.0/src/lzrans/crc32.h +9 -0
  23. lzrans-1.0.0/src/lzrans/dec.c +2307 -0
  24. lzrans-1.0.0/src/lzrans/enc.c +1975 -0
  25. lzrans-1.0.0/src/lzrans/enc_internal.h +168 -0
  26. lzrans-1.0.0/src/lzrans/filter.h +96 -0
  27. lzrans-1.0.0/src/lzrans/fse.c +146 -0
  28. lzrans-1.0.0/src/lzrans/fse.h +162 -0
  29. lzrans-1.0.0/src/lzrans/huf.c +583 -0
  30. lzrans-1.0.0/src/lzrans/huf.h +93 -0
  31. lzrans-1.0.0/src/lzrans/module.c +479 -0
  32. lzrans-1.0.0/src/lzrans/opt.c +1020 -0
  33. lzrans-1.0.0/src/lzrans/thread.h +103 -0
  34. lzrans-1.0.0/src/lzrans/x86.h +107 -0
  35. lzrans-1.0.0/src/lzrans/xxh64.h +111 -0
  36. lzrans-1.0.0/tests/test_cli.py +92 -0
  37. lzrans-1.0.0/tests/test_roundtrip.py +764 -0
  38. lzrans-1.0.0/tests/test_type7.py +178 -0
  39. lzrans-1.0.0/tests/test_vectors.py +130 -0
  40. lzrans-1.0.0/tests/test_version.py +22 -0
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ Versions follow semantic versioning from 1.0.0 (docs/INSTALL.md). The Python package,
4
+ liblzr and the lzr CLI share one version number.
5
+
6
+ ## 1.0.0 (unreleased)
7
+
8
+ First stable release. Frame format LZR 1.2 (frame version 7, docs/FORMAT.md),
9
+ frozen with golden vectors and a reference decoder.
10
+
11
+ - Levels -3..11: ultra-fast (-3..-1), zstd-class fast levels (0-10: Huffman + tANS,
12
+ block types 5/6), xz-class level 11 (LZMA-style token coding, block types 4/7).
13
+ - Streaming compression and decompression with bounded memory; windows up to 2 GiB
14
+ (`window_log` 18..31, decoder limit `max_window_log`, default 27).
15
+ - Multithreaded compression at every level, output identical for any thread count.
16
+ - Parallel decompression: segment reset points with seek index (levels 9-10 default
17
+ 48 MiB), pipelined entropy decoding, and level 11 chunked blocks (type 7, 16 MiB).
18
+ - Filters: x86 branch conversion, 16-bit delta, `filter="auto"`.
19
+ - XXH64 content checksum.
20
+ - liblzr C library (`include/lzr.h`), xz-style `lzr` CLI (tar `-I lzr`), man page,
21
+ pkg-config and CMake package files.
22
+ - Fuzzing: libFuzzer harnesses, ClusterFuzzLite on pull requests, OSS-Fuzz files.
23
+ - Windows support: Win32 threads (all threaded paths, same output as on Linux), MSVC
24
+ and MinGW-w64 builds (CMake, setup.py), `lzr.exe` with Unicode file names and
25
+ binary standard streams; Windows CI.
26
+ - Packaging: binary wheels for Linux and macOS (x86-64, arm64) and Windows (x86-64),
27
+ Python 3.10-3.14, and a Windows CLI zip on the GitHub release;
28
+ one version number shared by the package and the library (was 0.4.0.dev0 / 0.17.0).
29
+ - liblzr soname is now `liblzr.so.1`.
30
+
31
+ Development history before 1.0 (phases P1-P25) is in the README roadmap and the
32
+ pull requests.
lzrans-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The lzrans authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ # sdist: C sources and headers of the extension (src/lzrans/common.h includes include/lzr.h)
2
+ include include/lzr.h
3
+ recursive-include src/lzrans *.c *.h
4
+ include LICENSE CHANGELOG.md
lzrans-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.4
2
+ Name: lzrans
3
+ Version: 1.0.0
4
+ Summary: Streaming LZ compressor (LZR format): zstd-class fast levels, xz-class top level, parallel decode
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/qbit-core/lzrans
7
+ Project-URL: Source, https://github.com/qbit-core/lzrans
8
+ Project-URL: Changelog, https://github.com/qbit-core/lzrans/blob/main/CHANGELOG.md
9
+ Project-URL: Format specification, https://github.com/qbit-core/lzrans/blob/main/docs/FORMAT.md
10
+ Keywords: compression,lz77,rans,zstd,xz,lzma
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Programming Language :: C
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Topic :: System :: Archiving :: Compression
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest; extra == "test"
26
+ Dynamic: license-file
27
+
28
+ # lzrans
29
+
30
+ Streaming LZ77 compressor with two entropy back ends: a fast one
31
+ (Huffman + tANS, zstd-class decode speed) and an LZMA-class one. The core is C; Python uses it through a
32
+ CPython native extension.
33
+
34
+ **Goal:** levels 1-10 match zstd in ratio and speed (level 10: zstd -19);
35
+ level 11 beats xz -9 in ratio; level 0 is a zstd -3 class fast level,
36
+ levels -1..-3 are faster still (zstd -1 class ratio). Streaming throughout.
37
+ Status: 1.0.0 release candidate, frame format LZR 1.2 (see Roadmap, CHANGELOG.md).
38
+ Levels 7-11 were renumbered in v0.14: the old levels 7, 8, 9 are now 9, 10, 11.
39
+
40
+ ```python
41
+ import lzrans
42
+
43
+ blob = lzrans.compress(data, level=10) # -3 (fastest) .. 10: fast decode; 11: best ratio
44
+ blob = lzrans.compress(data, level=11, threads=4) # faster (levels 9-11: same bytes)
45
+ blob = lzrans.compress(exe_bytes, level=11, filter="x86") # x86/x86-64 code
46
+ blob = lzrans.compress(raw_image, level=11, filter="auto") # delta16 when it helps (16-bit samples)
47
+ assert lzrans.decompress(blob) == data # ChecksumError on checksum mismatch
48
+ assert lzrans.decompress(blob, threads=4) == data # parallel: segments, level 11 chunks, or blocks
49
+ blob = lzrans.compress(data, level=6, segment=16 << 20) # reset points every 16 MiB (any level)
50
+
51
+ # streaming, bounded memory
52
+ c = lzrans.Compressor(level=6)
53
+ out = b"".join(c.compress(chunk) for chunk in chunks) + c.flush()
54
+
55
+ d = lzrans.Decompressor()
56
+ for chunk in compressed_chunks:
57
+ sink.write(d.decompress(chunk))
58
+ assert d.eof
59
+ ```
60
+
61
+ ## Install
62
+
63
+ ```sh
64
+ pip install lzrans # binary wheels: Linux, macOS, Windows; Python 3.10-3.14
65
+ ```
66
+
67
+ Source builds, liblzr and the CLI: [docs/INSTALL.md](docs/INSTALL.md). Releases:
68
+ [docs/RELEASE.md](docs/RELEASE.md).
69
+
70
+ ## Build and test
71
+
72
+ ```sh
73
+ pip install -e .[test]
74
+ pytest # round-trip, streaming and corruption tests
75
+ make -C tests/c run # C core under ASan/UBSan, incl. mutated-input fuzzing
76
+ make fuzz # libFuzzer harnesses (clang); see docs/FUZZING.md
77
+ python bench/bench.py # vs zlib, xz and zstd (pip install zstandard)
78
+ ```
79
+
80
+ ## C library (liblzr) and command-line tool (lzr)
81
+
82
+ ```sh
83
+ make # build/c/liblzr.a, build/c/liblzr.so, build/c/lzr (+ unlzr, lzrcat)
84
+ make check # C API tests + CLI / tar round trips
85
+ sudo make install # PREFIX=/usr/local; lzr.h, liblzr, lzr.pc, man page
86
+ # or: cmake -B build/cmake && cmake --build build/cmake && ctest --test-dir build/cmake
87
+ # Windows (MSVC or MinGW): CMake as above, see docs/INSTALL.md
88
+ ```
89
+
90
+ `lzr` is used like `xz`: `lzr -9 -T4 file` writes `file.lzr` (input removed unless
91
+ `-k`; mode and times kept), `lzr -d file.lzr` restores it, `-c` writes to standard
92
+ output, `-t` tests, `-l` lists frames and segments. Levels `-0`..`-11` and
93
+ `--fast=1..3`; `--segment=SIZE`, `--chunk=SIZE`, `--window-log=N`, `--x86`, `--delta16`, `--auto-filter`, `--max-window-log=N`.
94
+ Standard input and output work, so it plugs into tar and pipes:
95
+
96
+ ```sh
97
+ tar -I 'lzr -11 -T0' -cf src.tar.lzr src/ # compress with tar
98
+ tar -I lzr -xf src.tar.lzr # extract
99
+ lzr -dc big.lzr | less # concatenated frames decode in sequence
100
+ ```
101
+
102
+ The output is byte-identical to the Python package for the same parameters
103
+ (regular files carry their size in the header, as `lzrans.compress`; pipes do
104
+ not, as `lzrans.Compressor`). Decompression with `-T` > 1 decodes in parallel
105
+ when the input is a regular file whose frames carry their size.
106
+
107
+ C API (`include/lzr.h`, link `-llzr`):
108
+
109
+ ```c
110
+ #include <lzr.h>
111
+ size_t cap = lzr_compress_bound(n), clen, dlen;
112
+ lzr_compress(dst, cap, &clen, src, n, 11); /* one-shot */
113
+ lzr_decompress(out, n, &dlen, dst, clen); /* LZR_OK or LZR_ERR_* */
114
+
115
+ lzr_cstream *cs = lzr_cstream_create(); /* streaming, bounded memory */
116
+ lzr_cstream_set(cs, LZR_C_LEVEL, 9);
117
+ lzr_cstream_set(cs, LZR_C_THREADS, 4);
118
+ lzr_inbuf in = {buf, len, 0};
119
+ lzr_outbuf out = {obuf, sizeof obuf, 0};
120
+ int r = lzr_compress_stream(cs, &out, &in, last ? LZR_FINISH : LZR_CONTINUE);
121
+ /* r: 1 = more output pending, 0 = done with this input (frame complete after LZR_FINISH) */
122
+ ```
123
+
124
+ `lzr_dstream` / `lzr_decompress_stream` mirror it (returns `LZR_FRAME_END` at the end
125
+ of each frame); `lzr_decompress_ds` decodes one frame with threads and a window limit;
126
+ `lzr_get_frame_info` parses a header. Contexts are independent and can be used
127
+ from different threads. The Python extension compiles the same core sources.
128
+
129
+ ## Design
130
+
131
+ | Stage | Implementation (`src/lzrans/`) |
132
+ |---|---|
133
+ | Match finding | Levels -1..-3 (`enc.c` `parse_block_fast1`): greedy single-hash finder like zstd's "fast": one table of the newest position per 6-byte hash (8K-16K entries, cache-resident) over a 0.5-1 MB window; the table slot and candidate bytes of the next position are loaded before the current one is resolved, a miss advances by 1-4 bytes plus one per 256 literals, and 2 positions per match are indexed. Level 0 (`enc.c` `parse_block_fast`): greedy double-hash finder over a 4 MB window, like zstd's "dfast": one table of the newest position per 8-byte hash and one per 5-byte hash (64K entries each); repeat offset 0 is tried one byte ahead, a short match is replaced by a long one starting a byte later when there is one, matches are extended backwards into the literals, only searched positions and 3 positions per match are indexed, and the search step grows by one every 256 literals. Levels 1-6 (`enc.c`): row match finder over a 1-16 MB window: a 5-byte hash picks a row of the 16-64 most recent positions plus an 8-bit tag per slot; tags are compared 16 at a time (SSE2, scalar fallback) and only tag hits are checked, with rows prefetched ahead of insertion. 3 repeat offsets are probed first; lazy matching (depth 0-2). Levels 7-8 (`enc.c` `row_gather`): the same rows (32-64 slots, 16 MB window) searched at every position (16-32 slots) for matches of increasing length; a match found one byte earlier is carried over one byte shorter, and inside a match of 16+ bytes only 2 slots are tried. Levels 9-11 (`opt.c`): binary tree (BT4) over a 32-64 MB window (level 9: 32 MB, 10-11: 64 MB; smaller when the input size is known and smaller) collecting all match lengths per position. |
134
+ | Parsing | Levels 7-11: price-based optimal parsing (forward DP over segments of up to 4096 positions, repeat offsets and coder state tracked per path). Levels 7-10 price with the static code lengths of the previous block's statistics; level 11 prices from a shadow copy of the adaptive model, advanced over the chosen tokens and re-tabulated per segment; a segment ends early (after >= 512 positions) where all paths meet. Besides tree matches the DP tries 2-3 byte matches at short distances, 1-byte "short rep" matches, and match + literal + rep0 / literal + rep0 combinations. Levels 7-8 skip the short matches, level 7 also the combinations, and both price every length only up to 12 (longer matches at full length). |
135
+ | Filter | `x86.h` (opt-in, `filter="x86"`): CALL (E8) rel32 operands with displacement < 2^25 are rewritten as absolute targets (mod 2^26), so repeated calls become repeated bytes. Bijective and streaming (holds back <= 4 bytes); the checksum covers the original content. ~4% smaller on an x86-64 shared object. |
136
+ | Filter | `filter.h` (opt-in, `filter="delta16"` or `"auto"`): little-endian 16-bit words replaced by their difference from the previous word (frame flag bit 3, format 1.1). Silesia x-ray +9.5%, mr +7.2% at level 11; other data gets worse, so `"auto"` tries both on four 64 KiB samples at level 0 and keeps the filter only at >= 4% gain. |
137
+ | Threads | Levels -3..6: the input is cut into 4 MB jobs compressed independently (each first indexes the preceding window, or half of a 16 MB window; level 0 every third position of it); repeat offsets start unknown and the first block of a job builds new tables, so the format is unchanged. Threads take jobs as they finish; output is identical for any thread count > 1 and within ~0.1% of one thread. When `compress()` gets the whole input at once, the jobs read it in place (no copy) except the last ones, and the checksum is computed while the helpers compress; the jobs and the output are the same as when streamed. Levels 7-8: one thread. Levels 9-11: hash buckets are split between threads (each tree only links positions of its own bucket, so no locks), and the next block is gathered in the background while the current one is parsed. Output is byte-identical for any thread count. |
138
+ | Tokens | Sequences of (literal run, match length, offset); offsets 0-2 are the repeat offsets. |
139
+ | Entropy coding, levels -3..10 | Block type 5, `huf.c` + `fse.c` (zstd-like): literals as 4 canonical Huffman streams (codes <= 11 bits, table reused across blocks when cheaper); literal-length / match-length / offset codes by table-driven ANS (tANS, 512 states, tables new / repeated / single-symbol per block) sharing one backward bit stream with the raw extra bits. |
140
+ | Context literals, levels 9-10 | Block type 6 = type 5 with another literal section (`huf.c` `hufc_*`): each literal is coded with one of up to 8 Huffman tables, picked by the byte before it through a 256-entry map. The encoder groups the 256 previous-byte values by a few rounds of k-means on the block's (previous byte, literal) counts (2, 4 or 8 groups, seeded by the top bits or by character classes), gives every symbol of the block a code in every table so later blocks can reuse them, and uses type 6 only when the literal section is >= 2% smaller than type 5's. Levels 7-8 keep type 5: there the decode cost (-11..-16%) outweighed +0.7%. The decoder decodes the literals while executing the sequences: one table lookup per literal, whose entry also holds the group of the decoded byte for the next one. |
141
+ | Entropy coding, level 11 | Block type 4, `arc.h`: the coding layer of LZMA on our tokens. One adaptive binary range coder (12-bit probabilities); a 12-value state of the last token kinds selects literal/match/rep decisions; literals use the previous byte's top 3 bits as context and, right after a match, the byte at rep0 ("matched literal"); match lengths 2-273 by low/mid/high trees per position & 3; distances by 6-bit slot (context: length) plus reverse-tree or direct + 4 aligned bits. The model, state and repeat offsets carry over between blocks. |
142
+ | Chunks, level 11 | Block type 7 (default, `chunk=` 1-32 MiB, default 16 MiB; `chunk=0` writes type 4; format 1.2, frame flag bit 4): type 4 coding cut into chunks whose model restarts and whose first block carries the state and repeat offsets. The LZ window is not cut. A literal uses the previous byte and the matched byte only if they are "known" inside the chunk (literals, and copies of known bytes from inside the chunk); otherwise it is coded with separate tables indexed by the last literal. `decompress(threads=N)` decodes chunks in parallel without the bytes before them, listing matches that leave unknown bytes, then replays those matches in chunk order. Silesia +0.09% / enwik8 +0.58% against type 4 (48 MiB segments: +0.38% / +1.0-2.6%). |
143
+ | Segments | `segment=` (levels 9-10 default 48 MiB, others off): the content is cut into segments compressed independently, each starting at a reset point, with a seek index (skippable block 0x80, FORMAT.md 12.3) before the end block. Segments are compressed in parallel (as many as fit in about 1 GiB of encoder memory; spare threads go to the match finders) and the output is identical for any thread count. Inputs no longer than one segment give exactly the unsegmented output. `decompress(threads=N)` finds the segments from the block headers and decodes them straight into the output buffer in parallel; the last block of each segment is decoded without wildcopy past its end, and the calling thread hashes finished segments in order. With fewer segments than threads (or none), each segment goes through the block pipeline below with its share of the threads, the segments side by side. |
144
+ | Decoding | `dec.c`: type 5: Huffman literals into an array (4 streams interleaved, one table lookup per symbol); then one loop decodes each sequence (one bit-stream read in the common case, branch-free repeat offsets) and copies with fixed 16-byte chunks. The hot loops are also compiled for BMI2 and picked at run time. Type 4: one token loop; tree bits (literals, lengths, distance slots) are decoded without branches (conditional moves), and the next tree node's probabilities are loaded before the current bit is known. One-shot `decompress` decodes straight into the output buffer (no history copy). Block pipeline (`decompress(threads=N)`, types 5-6, format unchanged): a pass over the block headers finds where each block's Huffman and tANS tables are described; worker threads then run the entropy stage several blocks ahead (type 5 literals into an array, the sequence stream into (literal length, match length, offset value) triples, tables rebuilt per worker only when they change) and fault in the block's output pages, while the calling thread executes the blocks in order (repeat offsets, literal and match copies, type 6 literals, which need the byte before each, and type 0 / 4 blocks whole) and decodes a later block itself when the next one is not ready; a worker hashes executed blocks in order. Same output and the same errors as one thread (a malformed header sends the frame to the serial decoder). |
145
+ | Streaming | Input is consumed and output produced block by block. Encoder memory is about 2x window + match tables (level 0: 512 KB; levels 1-6: 5 bytes per row slot, up to 40 MB at level 6, 40-48 MB at levels 7-8; levels 9-11: 8 bytes per window byte for the tree, about 680 MB at 64 MB, close to xz -9); decoder memory is about 2x window. |
146
+ | Integrity | Low 32 bits of XXH64 (`xxh64.h`, same value as zstd's frame checksum) in the end block, plus structural checks: every bit stream must be consumed exactly. (`lzrans.crc32` stays available as a zlib-compatible helper.) |
147
+
148
+ ## Frame format v7 = LZR 1.0 (little-endian)
149
+
150
+ The full specification, with golden test vectors and a pure-Python
151
+ reference decoder (`tools/refdec.py`), is [docs/FORMAT.md](docs/FORMAT.md);
152
+ this is a summary. Version 5 and 6 frames still decode.
153
+
154
+ ```
155
+ "LZRN" | version u8 = 7 | flags u8 | window_log u8 | reserved u8 | [content_size u64]
156
+ block*: type u8 | raw_len u32 | comp_len u32 | payload
157
+ type byte: bit 7 = skippable (raw_len 0, payload ignored); else bits 0-5 =
158
+ type, bit 6 = reset point (state reset, no references before it)
159
+ type 0 stored payload = raw bytes
160
+ type 2 end payload = low 32 bits of XXH64 (seed 0) of the whole content
161
+ type 4 tokens one adaptive range-coded token stream (arc.h); level 11 chunk=0
162
+ type 5 fast nseq u32 | nlit u32 | Huffman literal section (huf.h)
163
+ | if nseq: ll/ml/of table modes | backward tANS bit stream (fse.h)
164
+ type 6 ctx literals as type 5, literal section = mode u8 (0 new / 1 previous tables)
165
+ | mode 0: K u8, 256 nibbles (previous byte -> table), K tables
166
+ | stream size u32 | forward LSB-first stream (huf.h)
167
+ type 7 chunked type 4 tokens in chunks (flag CHUNKED); byte 0 = 1 chunk start
168
+ (state u8, rep0-2 u32) / 0 continuation | range-coded stream; level 11
169
+ types 8-63 newer formats: rejected as unsupported
170
+ ```
171
+
172
+ `flags`: bit 0 = encrypted (reserved), bit 1 = content size present
173
+ (set by one-shot `compress`), bit 2 = x86 filter applied to the content,
174
+ bit 3 = 16-bit delta filter (format 1.1), bits 4-7 = reserved for required features. Decoders reject unknown versions
175
+ and flags.
176
+
177
+ ## Encryption hook (not implemented yet)
178
+
179
+ Flag bit 0 (`lzrans.FLAG_ENCRYPTED`) is reserved for an AEAD envelope
180
+ (planned: libsodium XChaCha20-Poly1305, Argon2id key derivation): compress,
181
+ then encrypt per block; verify, then decompress. Frames with the flag set
182
+ are rejected for now.
183
+
184
+ ## Roadmap
185
+
186
+ | Phase | Change | Status |
187
+ |---|---|---|
188
+ | P1 | Streaming frame, large window, sequence tokens, repeat offsets | done |
189
+ | P2 | Binary-tree match finder + price-based optimal parsing | done |
190
+ | P3 | Adaptive literal coding (literal contexts, match-byte context), short repeat matches | done |
191
+ | P4 | x86 filter (binaries) | done |
192
+ | P5 | LZMA-style token coding (block type 4) + model-priced parsing: ratio at or above xz -9 | done |
193
+ | P6 | Block type 5 (Huffman + tANS) for levels 1-8: zstd -19 class ratio and speed | done |
194
+ | P7 | Row match finder for levels 1-6 (2-5x faster compression at about the same ratio) | done |
195
+ | P8 | Parallel jobs for levels 1-6 (threads > 1, format unchanged) + single-thread micro-optimizations | done |
196
+ | P9 | Type 4 decoder speed (branch-free tree decoding; format and output unchanged): 1.2-1.6x, about xz -9 decode speed or faster | done |
197
+ | P10 | Level 9 single-thread compression speed (parser and tree walk, output unchanged): 1.0-1.3x, about xz -9 except on source code | done |
198
+ | P11 | Level 0 (double-hash fast level, zstd -3 class: 0.84x its speed at 1 thread, 1.16x at 4 threads) + levels 1-6 1.0-1.1x faster with the same output | done |
199
+ | P12 | Same output, faster: job-mode threads overlap input copy/checksum with compression (L0 4 threads +17%, 1.22x zstd -3; L1-6 +5-8%); branch-free type 5 bit writers (L0 1 thread +8%) | done |
200
+ | P13 | Ultra-fast levels -1..-3 (single-hash finder; 4 threads 790-890 MB/s, ratio 3.2-3.8; about 0.65x zstd -1 speed at +3% ratio) + threaded one-shot compress() reads the input in place (L0 4 threads +23%, 1.42x zstd -3; L1-3 +9-16%; same output) | done |
201
+ | P15 | Redesign phase 1: levels 7-9 window 16 MB -> 32/64 MB (enwik8 L9 3.891 -> 4.032, above xz -9 4.022; Silesia L9 +0.4%, L8 +0.4%, L7 +0.7%; 1-thread compress 7-25% slower, memory about xz -9) | done |
202
+ | P16 | Redesign phase 2: cost-based block splitting for optimal-parse levels 7-8 (each block tried as up to 8 parts, kept only if smaller; format unchanged). Silesia L7 +0.4%, L8 +0.4% (xml +0.7%, mr +0.9%), speed unchanged; enwik8 unchanged | done |
203
+ | P17 | Redesign phase 3: levels 7-8 (new) = row finder feeding a light optimal parser; old levels 7-9 renumbered 9-11. Silesia 1 thread: L7 3.720 @ 5.5 MB/s (zstd -14 3.700 @ 5.4), L8 3.785 @ 3.6 MB/s (zstd -15 3.726 @ 3.7); enwik8 L7 +2.2% vs zstd -14 at 1.26x speed, L8 +3.4% vs zstd -15 at 1.28x. Speed gap between lazy level 6 and the tree levels 10x -> 3.3x | done |
204
+ | P18 | Frame format v6, block type 6: context literals for levels 9-10 (up to 8 Huffman tables chosen by the previous byte, picked per block, type 5 kept when the gain is under 2%). Silesia 1 thread vs v0.14: ratio +0.71% (L9) / +0.72% (L10, 4.027), compress -4% / 0%, decode -6% / -4%; enwik8 +0.02%. Levels 7-8 measured +0.7% at -11..-16% decode and were left on type 5 (output unchanged). v5 frames still decode | done |
205
+ | P19 | Format freeze: frame version 7 = LZR 1.0, specified in docs/FORMAT.md with golden test vectors (tests/vectors/) and a pure-Python reference decoder (tools/refdec.py). New in v7: reset points (parallel decoding / seeking later), skippable blocks, unsupported-vs-corrupt for newer block types, stored size of Huffman stream 3, complete Huffman codes only, comp_len <= raw_len. Compression output otherwise unchanged (+4 bytes per Huffman literal section). v5/v6 frames still decode | done |
206
+ | P20 | Parallel decompression: segment mode (reset points every 48 MiB by default at levels 9-11, `segment=` for any level) + seek index (skippable block 0x80, FORMAT.md 12.3) + `decompress(threads=N)`. Silesia L11: ratio -0.38% (still +0.6% vs xz -9), 4-thread decode 3.4x xz -9; L10 at zstd -19 ratio decodes 1.9x faster with 4 threads. enwik8 loses 1-2.6% (long-range repeats). Unsegmented output and 1-thread decode unchanged | done |
207
+ | P21 | Pipelined parallel decoding of one segment (format and output unchanged): `decompress(threads=N)` runs the type 5/6 entropy stage on worker threads ahead of the in-order block execution, and segments fewer than threads each get a pipeline. 4 threads vs 1 (v0.13): Silesia L8 2.5x, L10 2.3x (1325 MB/s, 1.6x zstd -19 at +0.4% ratio); enwik8 L10 unsegmented 2.8x (1140 MB/s, 1.8x zstd -19 at +5.1%), L10 default segments 2.1x. Single thread: sequences decoded 256 at a time before execution at windows >= 8 MB and for type 6 (enwik8 L10 1.37x, L6 1.16x, Silesia 1.03-1.05x). Level 11 (type 4) unchanged | done |
208
+ | P25 | Parallel decoding of level 11 without segment resets: block type 7 (format 1.2, frame flag CHUNKED), 16 MiB chunks by default (`chunk=`), level 11 no longer segmented by default. Silesia L11 4.388 (-0.08% vs type 4, +0.9% vs xz -9; 48 MiB segments were -0.38%), 4-thread decode 2.9x xz -9; enwik8 -0.57% vs type 4 (segments -2.5%), 4-thread decode 1.95x xz -9. 1-thread compress and decode about 5-7% slower | done |
209
+ | 1.0 | Release: one version (1.0.0) for package, liblzr and CLI; wheels for Linux, macOS and Windows (cibuildwheel), CI, LICENSE, CHANGELOG, docs/INSTALL.md and docs/RELEASE.md | in progress |
210
+ | 1.0 | Windows: Win32 threads behind a small thread layer (src/lzrans/thread.h), MSVC intrinsics for the GCC builtins, MSVC + MinGW builds (CMake, setup.py), `lzr.exe` file handling (UTF-8 names, binary stdio, mapped input, timestamps), Windows CI; compressed output unchanged | done |
lzrans-1.0.0/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # lzrans
2
+
3
+ Streaming LZ77 compressor with two entropy back ends: a fast one
4
+ (Huffman + tANS, zstd-class decode speed) and an LZMA-class one. The core is C; Python uses it through a
5
+ CPython native extension.
6
+
7
+ **Goal:** levels 1-10 match zstd in ratio and speed (level 10: zstd -19);
8
+ level 11 beats xz -9 in ratio; level 0 is a zstd -3 class fast level,
9
+ levels -1..-3 are faster still (zstd -1 class ratio). Streaming throughout.
10
+ Status: 1.0.0 release candidate, frame format LZR 1.2 (see Roadmap, CHANGELOG.md).
11
+ Levels 7-11 were renumbered in v0.14: the old levels 7, 8, 9 are now 9, 10, 11.
12
+
13
+ ```python
14
+ import lzrans
15
+
16
+ blob = lzrans.compress(data, level=10) # -3 (fastest) .. 10: fast decode; 11: best ratio
17
+ blob = lzrans.compress(data, level=11, threads=4) # faster (levels 9-11: same bytes)
18
+ blob = lzrans.compress(exe_bytes, level=11, filter="x86") # x86/x86-64 code
19
+ blob = lzrans.compress(raw_image, level=11, filter="auto") # delta16 when it helps (16-bit samples)
20
+ assert lzrans.decompress(blob) == data # ChecksumError on checksum mismatch
21
+ assert lzrans.decompress(blob, threads=4) == data # parallel: segments, level 11 chunks, or blocks
22
+ blob = lzrans.compress(data, level=6, segment=16 << 20) # reset points every 16 MiB (any level)
23
+
24
+ # streaming, bounded memory
25
+ c = lzrans.Compressor(level=6)
26
+ out = b"".join(c.compress(chunk) for chunk in chunks) + c.flush()
27
+
28
+ d = lzrans.Decompressor()
29
+ for chunk in compressed_chunks:
30
+ sink.write(d.decompress(chunk))
31
+ assert d.eof
32
+ ```
33
+
34
+ ## Install
35
+
36
+ ```sh
37
+ pip install lzrans # binary wheels: Linux, macOS, Windows; Python 3.10-3.14
38
+ ```
39
+
40
+ Source builds, liblzr and the CLI: [docs/INSTALL.md](docs/INSTALL.md). Releases:
41
+ [docs/RELEASE.md](docs/RELEASE.md).
42
+
43
+ ## Build and test
44
+
45
+ ```sh
46
+ pip install -e .[test]
47
+ pytest # round-trip, streaming and corruption tests
48
+ make -C tests/c run # C core under ASan/UBSan, incl. mutated-input fuzzing
49
+ make fuzz # libFuzzer harnesses (clang); see docs/FUZZING.md
50
+ python bench/bench.py # vs zlib, xz and zstd (pip install zstandard)
51
+ ```
52
+
53
+ ## C library (liblzr) and command-line tool (lzr)
54
+
55
+ ```sh
56
+ make # build/c/liblzr.a, build/c/liblzr.so, build/c/lzr (+ unlzr, lzrcat)
57
+ make check # C API tests + CLI / tar round trips
58
+ sudo make install # PREFIX=/usr/local; lzr.h, liblzr, lzr.pc, man page
59
+ # or: cmake -B build/cmake && cmake --build build/cmake && ctest --test-dir build/cmake
60
+ # Windows (MSVC or MinGW): CMake as above, see docs/INSTALL.md
61
+ ```
62
+
63
+ `lzr` is used like `xz`: `lzr -9 -T4 file` writes `file.lzr` (input removed unless
64
+ `-k`; mode and times kept), `lzr -d file.lzr` restores it, `-c` writes to standard
65
+ output, `-t` tests, `-l` lists frames and segments. Levels `-0`..`-11` and
66
+ `--fast=1..3`; `--segment=SIZE`, `--chunk=SIZE`, `--window-log=N`, `--x86`, `--delta16`, `--auto-filter`, `--max-window-log=N`.
67
+ Standard input and output work, so it plugs into tar and pipes:
68
+
69
+ ```sh
70
+ tar -I 'lzr -11 -T0' -cf src.tar.lzr src/ # compress with tar
71
+ tar -I lzr -xf src.tar.lzr # extract
72
+ lzr -dc big.lzr | less # concatenated frames decode in sequence
73
+ ```
74
+
75
+ The output is byte-identical to the Python package for the same parameters
76
+ (regular files carry their size in the header, as `lzrans.compress`; pipes do
77
+ not, as `lzrans.Compressor`). Decompression with `-T` > 1 decodes in parallel
78
+ when the input is a regular file whose frames carry their size.
79
+
80
+ C API (`include/lzr.h`, link `-llzr`):
81
+
82
+ ```c
83
+ #include <lzr.h>
84
+ size_t cap = lzr_compress_bound(n), clen, dlen;
85
+ lzr_compress(dst, cap, &clen, src, n, 11); /* one-shot */
86
+ lzr_decompress(out, n, &dlen, dst, clen); /* LZR_OK or LZR_ERR_* */
87
+
88
+ lzr_cstream *cs = lzr_cstream_create(); /* streaming, bounded memory */
89
+ lzr_cstream_set(cs, LZR_C_LEVEL, 9);
90
+ lzr_cstream_set(cs, LZR_C_THREADS, 4);
91
+ lzr_inbuf in = {buf, len, 0};
92
+ lzr_outbuf out = {obuf, sizeof obuf, 0};
93
+ int r = lzr_compress_stream(cs, &out, &in, last ? LZR_FINISH : LZR_CONTINUE);
94
+ /* r: 1 = more output pending, 0 = done with this input (frame complete after LZR_FINISH) */
95
+ ```
96
+
97
+ `lzr_dstream` / `lzr_decompress_stream` mirror it (returns `LZR_FRAME_END` at the end
98
+ of each frame); `lzr_decompress_ds` decodes one frame with threads and a window limit;
99
+ `lzr_get_frame_info` parses a header. Contexts are independent and can be used
100
+ from different threads. The Python extension compiles the same core sources.
101
+
102
+ ## Design
103
+
104
+ | Stage | Implementation (`src/lzrans/`) |
105
+ |---|---|
106
+ | Match finding | Levels -1..-3 (`enc.c` `parse_block_fast1`): greedy single-hash finder like zstd's "fast": one table of the newest position per 6-byte hash (8K-16K entries, cache-resident) over a 0.5-1 MB window; the table slot and candidate bytes of the next position are loaded before the current one is resolved, a miss advances by 1-4 bytes plus one per 256 literals, and 2 positions per match are indexed. Level 0 (`enc.c` `parse_block_fast`): greedy double-hash finder over a 4 MB window, like zstd's "dfast": one table of the newest position per 8-byte hash and one per 5-byte hash (64K entries each); repeat offset 0 is tried one byte ahead, a short match is replaced by a long one starting a byte later when there is one, matches are extended backwards into the literals, only searched positions and 3 positions per match are indexed, and the search step grows by one every 256 literals. Levels 1-6 (`enc.c`): row match finder over a 1-16 MB window: a 5-byte hash picks a row of the 16-64 most recent positions plus an 8-bit tag per slot; tags are compared 16 at a time (SSE2, scalar fallback) and only tag hits are checked, with rows prefetched ahead of insertion. 3 repeat offsets are probed first; lazy matching (depth 0-2). Levels 7-8 (`enc.c` `row_gather`): the same rows (32-64 slots, 16 MB window) searched at every position (16-32 slots) for matches of increasing length; a match found one byte earlier is carried over one byte shorter, and inside a match of 16+ bytes only 2 slots are tried. Levels 9-11 (`opt.c`): binary tree (BT4) over a 32-64 MB window (level 9: 32 MB, 10-11: 64 MB; smaller when the input size is known and smaller) collecting all match lengths per position. |
107
+ | Parsing | Levels 7-11: price-based optimal parsing (forward DP over segments of up to 4096 positions, repeat offsets and coder state tracked per path). Levels 7-10 price with the static code lengths of the previous block's statistics; level 11 prices from a shadow copy of the adaptive model, advanced over the chosen tokens and re-tabulated per segment; a segment ends early (after >= 512 positions) where all paths meet. Besides tree matches the DP tries 2-3 byte matches at short distances, 1-byte "short rep" matches, and match + literal + rep0 / literal + rep0 combinations. Levels 7-8 skip the short matches, level 7 also the combinations, and both price every length only up to 12 (longer matches at full length). |
108
+ | Filter | `x86.h` (opt-in, `filter="x86"`): CALL (E8) rel32 operands with displacement < 2^25 are rewritten as absolute targets (mod 2^26), so repeated calls become repeated bytes. Bijective and streaming (holds back <= 4 bytes); the checksum covers the original content. ~4% smaller on an x86-64 shared object. |
109
+ | Filter | `filter.h` (opt-in, `filter="delta16"` or `"auto"`): little-endian 16-bit words replaced by their difference from the previous word (frame flag bit 3, format 1.1). Silesia x-ray +9.5%, mr +7.2% at level 11; other data gets worse, so `"auto"` tries both on four 64 KiB samples at level 0 and keeps the filter only at >= 4% gain. |
110
+ | Threads | Levels -3..6: the input is cut into 4 MB jobs compressed independently (each first indexes the preceding window, or half of a 16 MB window; level 0 every third position of it); repeat offsets start unknown and the first block of a job builds new tables, so the format is unchanged. Threads take jobs as they finish; output is identical for any thread count > 1 and within ~0.1% of one thread. When `compress()` gets the whole input at once, the jobs read it in place (no copy) except the last ones, and the checksum is computed while the helpers compress; the jobs and the output are the same as when streamed. Levels 7-8: one thread. Levels 9-11: hash buckets are split between threads (each tree only links positions of its own bucket, so no locks), and the next block is gathered in the background while the current one is parsed. Output is byte-identical for any thread count. |
111
+ | Tokens | Sequences of (literal run, match length, offset); offsets 0-2 are the repeat offsets. |
112
+ | Entropy coding, levels -3..10 | Block type 5, `huf.c` + `fse.c` (zstd-like): literals as 4 canonical Huffman streams (codes <= 11 bits, table reused across blocks when cheaper); literal-length / match-length / offset codes by table-driven ANS (tANS, 512 states, tables new / repeated / single-symbol per block) sharing one backward bit stream with the raw extra bits. |
113
+ | Context literals, levels 9-10 | Block type 6 = type 5 with another literal section (`huf.c` `hufc_*`): each literal is coded with one of up to 8 Huffman tables, picked by the byte before it through a 256-entry map. The encoder groups the 256 previous-byte values by a few rounds of k-means on the block's (previous byte, literal) counts (2, 4 or 8 groups, seeded by the top bits or by character classes), gives every symbol of the block a code in every table so later blocks can reuse them, and uses type 6 only when the literal section is >= 2% smaller than type 5's. Levels 7-8 keep type 5: there the decode cost (-11..-16%) outweighed +0.7%. The decoder decodes the literals while executing the sequences: one table lookup per literal, whose entry also holds the group of the decoded byte for the next one. |
114
+ | Entropy coding, level 11 | Block type 4, `arc.h`: the coding layer of LZMA on our tokens. One adaptive binary range coder (12-bit probabilities); a 12-value state of the last token kinds selects literal/match/rep decisions; literals use the previous byte's top 3 bits as context and, right after a match, the byte at rep0 ("matched literal"); match lengths 2-273 by low/mid/high trees per position & 3; distances by 6-bit slot (context: length) plus reverse-tree or direct + 4 aligned bits. The model, state and repeat offsets carry over between blocks. |
115
+ | Chunks, level 11 | Block type 7 (default, `chunk=` 1-32 MiB, default 16 MiB; `chunk=0` writes type 4; format 1.2, frame flag bit 4): type 4 coding cut into chunks whose model restarts and whose first block carries the state and repeat offsets. The LZ window is not cut. A literal uses the previous byte and the matched byte only if they are "known" inside the chunk (literals, and copies of known bytes from inside the chunk); otherwise it is coded with separate tables indexed by the last literal. `decompress(threads=N)` decodes chunks in parallel without the bytes before them, listing matches that leave unknown bytes, then replays those matches in chunk order. Silesia +0.09% / enwik8 +0.58% against type 4 (48 MiB segments: +0.38% / +1.0-2.6%). |
116
+ | Segments | `segment=` (levels 9-10 default 48 MiB, others off): the content is cut into segments compressed independently, each starting at a reset point, with a seek index (skippable block 0x80, FORMAT.md 12.3) before the end block. Segments are compressed in parallel (as many as fit in about 1 GiB of encoder memory; spare threads go to the match finders) and the output is identical for any thread count. Inputs no longer than one segment give exactly the unsegmented output. `decompress(threads=N)` finds the segments from the block headers and decodes them straight into the output buffer in parallel; the last block of each segment is decoded without wildcopy past its end, and the calling thread hashes finished segments in order. With fewer segments than threads (or none), each segment goes through the block pipeline below with its share of the threads, the segments side by side. |
117
+ | Decoding | `dec.c`: type 5: Huffman literals into an array (4 streams interleaved, one table lookup per symbol); then one loop decodes each sequence (one bit-stream read in the common case, branch-free repeat offsets) and copies with fixed 16-byte chunks. The hot loops are also compiled for BMI2 and picked at run time. Type 4: one token loop; tree bits (literals, lengths, distance slots) are decoded without branches (conditional moves), and the next tree node's probabilities are loaded before the current bit is known. One-shot `decompress` decodes straight into the output buffer (no history copy). Block pipeline (`decompress(threads=N)`, types 5-6, format unchanged): a pass over the block headers finds where each block's Huffman and tANS tables are described; worker threads then run the entropy stage several blocks ahead (type 5 literals into an array, the sequence stream into (literal length, match length, offset value) triples, tables rebuilt per worker only when they change) and fault in the block's output pages, while the calling thread executes the blocks in order (repeat offsets, literal and match copies, type 6 literals, which need the byte before each, and type 0 / 4 blocks whole) and decodes a later block itself when the next one is not ready; a worker hashes executed blocks in order. Same output and the same errors as one thread (a malformed header sends the frame to the serial decoder). |
118
+ | Streaming | Input is consumed and output produced block by block. Encoder memory is about 2x window + match tables (level 0: 512 KB; levels 1-6: 5 bytes per row slot, up to 40 MB at level 6, 40-48 MB at levels 7-8; levels 9-11: 8 bytes per window byte for the tree, about 680 MB at 64 MB, close to xz -9); decoder memory is about 2x window. |
119
+ | Integrity | Low 32 bits of XXH64 (`xxh64.h`, same value as zstd's frame checksum) in the end block, plus structural checks: every bit stream must be consumed exactly. (`lzrans.crc32` stays available as a zlib-compatible helper.) |
120
+
121
+ ## Frame format v7 = LZR 1.0 (little-endian)
122
+
123
+ The full specification, with golden test vectors and a pure-Python
124
+ reference decoder (`tools/refdec.py`), is [docs/FORMAT.md](docs/FORMAT.md);
125
+ this is a summary. Version 5 and 6 frames still decode.
126
+
127
+ ```
128
+ "LZRN" | version u8 = 7 | flags u8 | window_log u8 | reserved u8 | [content_size u64]
129
+ block*: type u8 | raw_len u32 | comp_len u32 | payload
130
+ type byte: bit 7 = skippable (raw_len 0, payload ignored); else bits 0-5 =
131
+ type, bit 6 = reset point (state reset, no references before it)
132
+ type 0 stored payload = raw bytes
133
+ type 2 end payload = low 32 bits of XXH64 (seed 0) of the whole content
134
+ type 4 tokens one adaptive range-coded token stream (arc.h); level 11 chunk=0
135
+ type 5 fast nseq u32 | nlit u32 | Huffman literal section (huf.h)
136
+ | if nseq: ll/ml/of table modes | backward tANS bit stream (fse.h)
137
+ type 6 ctx literals as type 5, literal section = mode u8 (0 new / 1 previous tables)
138
+ | mode 0: K u8, 256 nibbles (previous byte -> table), K tables
139
+ | stream size u32 | forward LSB-first stream (huf.h)
140
+ type 7 chunked type 4 tokens in chunks (flag CHUNKED); byte 0 = 1 chunk start
141
+ (state u8, rep0-2 u32) / 0 continuation | range-coded stream; level 11
142
+ types 8-63 newer formats: rejected as unsupported
143
+ ```
144
+
145
+ `flags`: bit 0 = encrypted (reserved), bit 1 = content size present
146
+ (set by one-shot `compress`), bit 2 = x86 filter applied to the content,
147
+ bit 3 = 16-bit delta filter (format 1.1), bits 4-7 = reserved for required features. Decoders reject unknown versions
148
+ and flags.
149
+
150
+ ## Encryption hook (not implemented yet)
151
+
152
+ Flag bit 0 (`lzrans.FLAG_ENCRYPTED`) is reserved for an AEAD envelope
153
+ (planned: libsodium XChaCha20-Poly1305, Argon2id key derivation): compress,
154
+ then encrypt per block; verify, then decompress. Frames with the flag set
155
+ are rejected for now.
156
+
157
+ ## Roadmap
158
+
159
+ | Phase | Change | Status |
160
+ |---|---|---|
161
+ | P1 | Streaming frame, large window, sequence tokens, repeat offsets | done |
162
+ | P2 | Binary-tree match finder + price-based optimal parsing | done |
163
+ | P3 | Adaptive literal coding (literal contexts, match-byte context), short repeat matches | done |
164
+ | P4 | x86 filter (binaries) | done |
165
+ | P5 | LZMA-style token coding (block type 4) + model-priced parsing: ratio at or above xz -9 | done |
166
+ | P6 | Block type 5 (Huffman + tANS) for levels 1-8: zstd -19 class ratio and speed | done |
167
+ | P7 | Row match finder for levels 1-6 (2-5x faster compression at about the same ratio) | done |
168
+ | P8 | Parallel jobs for levels 1-6 (threads > 1, format unchanged) + single-thread micro-optimizations | done |
169
+ | P9 | Type 4 decoder speed (branch-free tree decoding; format and output unchanged): 1.2-1.6x, about xz -9 decode speed or faster | done |
170
+ | P10 | Level 9 single-thread compression speed (parser and tree walk, output unchanged): 1.0-1.3x, about xz -9 except on source code | done |
171
+ | P11 | Level 0 (double-hash fast level, zstd -3 class: 0.84x its speed at 1 thread, 1.16x at 4 threads) + levels 1-6 1.0-1.1x faster with the same output | done |
172
+ | P12 | Same output, faster: job-mode threads overlap input copy/checksum with compression (L0 4 threads +17%, 1.22x zstd -3; L1-6 +5-8%); branch-free type 5 bit writers (L0 1 thread +8%) | done |
173
+ | P13 | Ultra-fast levels -1..-3 (single-hash finder; 4 threads 790-890 MB/s, ratio 3.2-3.8; about 0.65x zstd -1 speed at +3% ratio) + threaded one-shot compress() reads the input in place (L0 4 threads +23%, 1.42x zstd -3; L1-3 +9-16%; same output) | done |
174
+ | P15 | Redesign phase 1: levels 7-9 window 16 MB -> 32/64 MB (enwik8 L9 3.891 -> 4.032, above xz -9 4.022; Silesia L9 +0.4%, L8 +0.4%, L7 +0.7%; 1-thread compress 7-25% slower, memory about xz -9) | done |
175
+ | P16 | Redesign phase 2: cost-based block splitting for optimal-parse levels 7-8 (each block tried as up to 8 parts, kept only if smaller; format unchanged). Silesia L7 +0.4%, L8 +0.4% (xml +0.7%, mr +0.9%), speed unchanged; enwik8 unchanged | done |
176
+ | P17 | Redesign phase 3: levels 7-8 (new) = row finder feeding a light optimal parser; old levels 7-9 renumbered 9-11. Silesia 1 thread: L7 3.720 @ 5.5 MB/s (zstd -14 3.700 @ 5.4), L8 3.785 @ 3.6 MB/s (zstd -15 3.726 @ 3.7); enwik8 L7 +2.2% vs zstd -14 at 1.26x speed, L8 +3.4% vs zstd -15 at 1.28x. Speed gap between lazy level 6 and the tree levels 10x -> 3.3x | done |
177
+ | P18 | Frame format v6, block type 6: context literals for levels 9-10 (up to 8 Huffman tables chosen by the previous byte, picked per block, type 5 kept when the gain is under 2%). Silesia 1 thread vs v0.14: ratio +0.71% (L9) / +0.72% (L10, 4.027), compress -4% / 0%, decode -6% / -4%; enwik8 +0.02%. Levels 7-8 measured +0.7% at -11..-16% decode and were left on type 5 (output unchanged). v5 frames still decode | done |
178
+ | P19 | Format freeze: frame version 7 = LZR 1.0, specified in docs/FORMAT.md with golden test vectors (tests/vectors/) and a pure-Python reference decoder (tools/refdec.py). New in v7: reset points (parallel decoding / seeking later), skippable blocks, unsupported-vs-corrupt for newer block types, stored size of Huffman stream 3, complete Huffman codes only, comp_len <= raw_len. Compression output otherwise unchanged (+4 bytes per Huffman literal section). v5/v6 frames still decode | done |
179
+ | P20 | Parallel decompression: segment mode (reset points every 48 MiB by default at levels 9-11, `segment=` for any level) + seek index (skippable block 0x80, FORMAT.md 12.3) + `decompress(threads=N)`. Silesia L11: ratio -0.38% (still +0.6% vs xz -9), 4-thread decode 3.4x xz -9; L10 at zstd -19 ratio decodes 1.9x faster with 4 threads. enwik8 loses 1-2.6% (long-range repeats). Unsegmented output and 1-thread decode unchanged | done |
180
+ | P21 | Pipelined parallel decoding of one segment (format and output unchanged): `decompress(threads=N)` runs the type 5/6 entropy stage on worker threads ahead of the in-order block execution, and segments fewer than threads each get a pipeline. 4 threads vs 1 (v0.13): Silesia L8 2.5x, L10 2.3x (1325 MB/s, 1.6x zstd -19 at +0.4% ratio); enwik8 L10 unsegmented 2.8x (1140 MB/s, 1.8x zstd -19 at +5.1%), L10 default segments 2.1x. Single thread: sequences decoded 256 at a time before execution at windows >= 8 MB and for type 6 (enwik8 L10 1.37x, L6 1.16x, Silesia 1.03-1.05x). Level 11 (type 4) unchanged | done |
181
+ | P25 | Parallel decoding of level 11 without segment resets: block type 7 (format 1.2, frame flag CHUNKED), 16 MiB chunks by default (`chunk=`), level 11 no longer segmented by default. Silesia L11 4.388 (-0.08% vs type 4, +0.9% vs xz -9; 48 MiB segments were -0.38%), 4-thread decode 2.9x xz -9; enwik8 -0.57% vs type 4 (segments -2.5%), 4-thread decode 1.95x xz -9. 1-thread compress and decode about 5-7% slower | done |
182
+ | 1.0 | Release: one version (1.0.0) for package, liblzr and CLI; wheels for Linux, macOS and Windows (cibuildwheel), CI, LICENSE, CHANGELOG, docs/INSTALL.md and docs/RELEASE.md | in progress |
183
+ | 1.0 | Windows: Win32 threads behind a small thread layer (src/lzrans/thread.h), MSVC intrinsics for the GCC builtins, MSVC + MinGW builds (CMake, setup.py), `lzr.exe` file handling (UTF-8 names, binary stdio, mapped input, timestamps), Windows CI; compressed output unchanged | done |