From f11f5f4825b660f75e94188bc665a27a949ef125 Mon Sep 17 00:00:00 2001 From: iris-ai <4+iris-ai@noreply.localhost> Date: Wed, 16 Sep 2026 04:06:46 -0400 Subject: [PATCH] Divide twice in a range's inverse, not four times Which end of the answer each bound comes from is known from the sign of the fraction before dividing; taking the min and max of four divisions asked the question twice. A division is the most expensive thing in that function and it runs per child per axis. `many` 0.283 ms a frame to 0.278. Small, and strictly less work. Co-Authored-By: Claude Opus 5 --- core/src/ui/holds.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/ui/holds.rs b/core/src/ui/holds.rs index bafeea2..975bc8b 100644 --- a/core/src/ui/holds.rs +++ b/core/src/ui/holds.rs @@ -64,11 +64,12 @@ impl Holds { let half_rel = REL_SHIFT - 1; let lo = ((self.lo.raw() as i64 - px) * 2 - 3) << half_rel; let hi = ((self.hi.raw() as i64 - px) * 2 + 3) << half_rel; - let (a, b) = (div_toward(lo, rel, true), div_toward(hi, rel, false)); - let (c, d) = (div_toward(lo, rel, false), div_toward(hi, rel, true)); + // Dividing by a negative turns the ends around, so which end each + // bound comes from is decided before dividing rather than by taking + // the min and max of four divisions. match rel > 0 { - true => Self::raws(a, b), - false => Self::raws(d, c), + true => Self::raws(div_toward(lo, rel, true), div_toward(hi, rel, false)), + false => Self::raws(div_toward(hi, rel, true), div_toward(lo, rel, false)), } }