mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
std/brotli: speed up qualities 0 to 9 and the decoder
Encoder (output stays byte-exact with libbrotlienc v1.2.1): - H58/H68 (q5-6): match the tags 8 at a time (SWAR, like GetMatchingTagMask's non-SSE2 code) and visit the matches with a de Bruijn ctz; inline the bucket entry check into the H5/H6 and H58/H68 loops, caching the 4 bytes compared at best_len; a dedicated H58/H68 store and hash. - find_last_distances caches the current byte at best_len. - ctz64 and a branch-free log2_floor_non_zero (de Bruijn tables), and find_match_length_with_limit uses ctz. - load32le, load64le, peek_u16, poke_u16 and poke_u32 use one bounds check each. Decoder (same output and statuses): - The literal fast path keeps pos and the counts in local variables. - Copies of at most 16 bytes, with a distance of at least 16, copy 16 bytes (like the C code; the window gap keeps the extra bytes unread). script/manual-test-brotli-float.c also checks log2_floor_non_zero (every u32) and ctz64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZ978BikvkegL2JUkqoB1e
This commit is contained in:
8 files changed
+716
-377
No files matched your search
+16
-8
@@ -883,7 +883,9 @@ by both this package's decoder and libbrotlidec.
|
||||
`script/manual-test-brotli-float.c` checks the encoder's package-private
|
||||
float fast paths (`encode_float.wuffs`, which spare the hot loops the
|
||||
cross-package `std/softfloat` calls) against the C compiler's hardware float
|
||||
and double arithmetic, for operands biased towards their edge cases.
|
||||
and double arithmetic, for operands biased towards their edge cases, and
|
||||
checks the integer bit helpers (`log2_floor_non_zero` for every 32-bit value,
|
||||
and `ctz64`).
|
||||
`script/manual-test-brotli-encoder-parity.c` runs a larger grid over every
|
||||
file in `test/data/brotli`, some larger files in `test/data` (up to about
|
||||
400 KiB) and some synthetic inputs (up to 1 MiB). Its `-q=LO-HI` and
|
||||
@@ -1131,13 +1133,19 @@ metablock) for as long as it needs the results.
|
||||
- `workbuf_len` is a worst case (or, at qualities 10 and 11, a practical
|
||||
bound). A future option could take the input length (like the C code's
|
||||
size hint) to give a tighter bound.
|
||||
- Speed. Compressing the 3 MiB `test/data/harvesters.bmp` in one call (on
|
||||
x86-64, lgwin 22), the Wuffs encoder takes about 1.2 times libbrotlienc's
|
||||
time at quality 5, 1.7 times at quality 9, 4 times at quality 10 and 3.5
|
||||
times at quality 11 (on text, 2 to 3 times at qualities 10 and 11), mostly
|
||||
because of the soft float arithmetic in the Zopfli cost model, the block
|
||||
splitter and histogram clustering. Decoding takes about 1.2 times
|
||||
libbrotlidec's time.
|
||||
- Speed. On a mix of text, JSON, map data, an image and an ISO image (on
|
||||
x86-64, lgwin 22, one call each, reusing the workbuf), the Wuffs encoder
|
||||
takes about 1.2 to 1.8 times libbrotlienc's time at qualities 0 to 8 (about
|
||||
1.8 times at the qualities 4 to 6 that web servers use for on-the-fly
|
||||
compression) and about the same time at quality 9. At qualities 10 and 11
|
||||
it takes about 2 times libbrotlienc's time on text and 3.5 to 4 times on
|
||||
images (such as the 3 MiB `test/data/harvesters.bmp`), mostly because of
|
||||
the soft float arithmetic in the Zopfli cost model, the block splitter and
|
||||
histogram clustering. Decoding takes about 1.2 to 1.6 times libbrotlidec's
|
||||
time. The workbuf is sized for the window (about 48 to 62 MiB at lgwin 22
|
||||
and qualities 5 to 9), so callers that compress many small inputs should
|
||||
reuse it: allocating and first touching a fresh one for each call costs
|
||||
more than the compression of a small input.
|
||||
- Serialized (shared) dictionaries, which only an experimental
|
||||
(`BROTLI_EXPERIMENTAL`) libbrotlienc build supports.
|
||||
- Changing parameters mid-stream.
|
||||
|
||||
Reference in new issue
Block a user