mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
std/brotli: fill the FastLog2 caches lazily
Each bit_cost (one in the encoder, one in its metablock_builder) has a 64Ki-entry FastLog2 cache. The metablock_builder filled all of it before building each quality 10 or 11 metablock (about 20 ms per encoder, since each entry is an exact software log2), and the encoder's own cache was never filled, so the quality 10 and 11 literal cost estimates computed one software log2 per input byte. Instead, a bitmap (zeroed when the struct is initialized) records which cache entries are valid, and the new fast_log2_memo fills an entry the first time it is needed. Typically only a few thousand entries are used. bits_entropy, population_cost and their callers become impure (!) to call it. The values are computed by the same functions, so the results are unchanged. On alice29 at quality 10, the encoder executes about 20% fewer instructions, and a 1000-byte input takes 6 ms instead of 21 ms.
This commit is contained in:
9 files changed
+208
-157
No files matched your search
@@ -896,7 +896,12 @@ uses it at qualities 10 and 11 (and its smaller helpers at lower
|
||||
qualities). Its
|
||||
fixed-size state (about 0.8 MiB: FindBlocks' cost arrays and a 64Ki-entry
|
||||
FastLog2 cache in its `bit_cost`) lives in the struct; everything that the C
|
||||
code allocates on the heap lives in a caller-supplied workbuf.
|
||||
code allocates on the heap lives in a caller-supplied workbuf. The FastLog2
|
||||
cache (like the encoder's own `bit_cost` one) is filled lazily, one entry at
|
||||
a time, when `fast_log2_memo` first needs that entry (a bitmap, zeroed when the
|
||||
struct is initialized, records which entries are valid): typically only a few
|
||||
thousand of the 65536 entries are ever used, and each one costs a (slow, exact)
|
||||
software `log2`.
|
||||
|
||||
Data formats (all little-endian, matching the C structs' memory layout on a
|
||||
64-bit little-endian machine, so that results can be compared with `memcmp`):
|
||||
|
||||
Reference in new issue
Block a user