From 11ef0e6b049a7b2bfbb04206f2751f0c28d5b4b6 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 10 Oct 2026 15:35:13 -0400 Subject: [PATCH] Maintainer fix-up: compare clearly different numbers directly, skipping the 15-digit text round trip on the sort/lookup hot path Co-Authored-By: Claude Opus 5.5 --- crates/core/src/value.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/core/src/value.rs b/crates/core/src/value.rs index 53f707d..390800f 100644 --- a/crates/core/src/value.rs +++ b/crates/core/src/value.rs @@ -311,6 +311,11 @@ pub fn compare_numbers(a: f64, b: f64) -> Ordering { if a == b { return Ordering::Equal; } + // Numbers further apart than the 15th digit can't round together, and rounding keeps their + // order: skip the text round trip (this is on the sort and lookup hot path). + if (a - b).abs() > a.abs().max(b.abs()) * 1e-13 { + return a.partial_cmp(&b).unwrap_or(Ordering::Equal); + } round15(a).partial_cmp(&round15(b)).unwrap_or(Ordering::Equal) }