mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-29 20:48:33 -06:00
`median_row` (the running median under process V2's highlights/shadows base) kept a sorted window of f32 and, per pixel, found the leaving and entering values with two binary searches on `total_cmp`, then `remove` + `insert`. The searches mispredicted on most steps. Now the window holds `i32` keys that order exactly like `f32::total_cmp` (the same transform it applies), both ranks come from one branch-free counting pass the compiler vectorizes, and one `copy_within` moves the keys between them. Equal keys are equal bits, so the output is unchanged bit for bit. 24 MP Sony A7 III log luminance, one P-core, interleaved: r = 9 (export) 1977-2027 ms -> 912-958 ms, r = 3 1249-1292 -> 658-724, r = 24 2180-2261 -> 972-1030. All cores, r = 9: 170-188 -> 86-102 ms. The GPU path has its own median and is untouched. New test: special values (NaN of both signs, signed zeros, infinities), long ties and planes narrower than the window match a per-pixel sorted median bit for bit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0121DZuByhKyGLHw5C9JkUue