mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-25 18:47:07 -06:00
Cause: quantize_px rounded with `(v + 0.5) as u32 as f32`. Converting back from u32 is several instructions in V8's wasm code on x86 (no unsigned conversion), so quantising a 1080p layer took about 15 ms in the browser: every 8/16 bpc layer is quantised after its source and every effect, and the CPU compositor quantises the comp after every layer. Fix: round_half_up uses floor in wasm (one instruction there) and keeps the integer conversion elsewhere (x86-64's baseline has no floor instruction, where floor is slower). The values are the same: both round non-negative values half up. About 1.5x faster quantising in the browser (15 -> 10 ms per 1080p layer in a wasm micro-benchmark), unchanged on the desktop. Tests: color::tests::rounding_forms_agree: both forms agree on 0..=levels in sixteenths (exact halves included) and on 100 001 products, at 8 and 16 bpc. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>