From 4f5e27cba94f2c47b9d56537780ec2f03d69a89e Mon Sep 17 00:00:00 2001 From: iris-ai <4+iris-ai@noreply.localhost> Date: Wed, 16 Sep 2026 04:13:51 -0400 Subject: [PATCH] Do not divide by one to remap a box that spans its parent A retained part is re-expressed as a fraction of its new box by dividing by the old box's extent, and that extent is one whenever the box spans the whole of its parent's -- which is the common shape. An integer division is the most expensive thing in `apply_scalar` and it ran twice per span. `perf stat -e instructions:u` over 500 frames: `many` 1,938,264,572 to 1,886,265,821, `scroll` 452,517,906 to 444,792,314. Tried first and reverted: short-circuiting a fraction of nought or one, at either end of the box. That is not the common case, and the two comparisons cost 17% more than the divisions they were meant to save. Checked: fmt, clippy, 105 tests, three shrinker cases at 300 seeds, 100 generated seeds. Co-Authored-By: Claude Opus 5 --- core/src/ui/render_state.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/ui/render_state.rs b/core/src/ui/render_state.rs index 7b87280..d70d994 100644 --- a/core/src/ui/render_state.rs +++ b/core/src/ui/render_state.rs @@ -1090,7 +1090,13 @@ impl RegionRemap { if from.len() == to.len() || extent == Rel::ZERO { return scalar + to.start - from.start; } - let fraction = (scalar.rel - from.start.rel) / extent; + // A box that spans the whole of its parent's is the common one, and + // dividing by one is the expensive way to write a subtraction. + let offset = scalar.rel - from.start.rel; + let fraction = match extent == Rel::ONE { + true => offset, + false => offset / extent, + }; let from_px = fraction.lerp(from.start.px, from.end.px); let to_rel = fraction.lerp(to.start.rel, to.end.rel); let to_px = fraction.lerp(to.start.px, to.end.px);