mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
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.