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 <noreply@anthropic.com>
This commit is contained in:
1 parent
11c55bcef9
commit
4f5e27cba9
1 file changed
+7
-1
@@ -1090,7 +1090,13 @@ impl RegionRemap {
|
|||||||
if from.len() == to.len() || extent == Rel::ZERO {
|
if from.len() == to.len() || extent == Rel::ZERO {
|
||||||
return scalar + to.start - from.start;
|
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 from_px = fraction.lerp(from.start.px, from.end.px);
|
||||||
let to_rel = fraction.lerp(to.start.rel, to.end.rel);
|
let to_rel = fraction.lerp(to.start.rel, to.end.rel);
|
||||||
let to_px = fraction.lerp(to.start.px, to.end.px);
|
let to_px = fraction.lerp(to.start.px, to.end.px);
|
||||||
|
|||||||
Reference in new issue
Block a user