From 81b5e683f9f526689f7e9f60100db4f48f4fe2a6 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Sat, 11 Jul 2026 09:29:17 -0600 Subject: [PATCH] perf: optimize lcm in datafusion-functions --- datafusion/functions/src/math/common.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datafusion/functions/src/math/common.rs b/datafusion/functions/src/math/common.rs index 9bb6f6fe1e35c..f7093eee893c2 100644 --- a/datafusion/functions/src/math/common.rs +++ b/datafusion/functions/src/math/common.rs @@ -140,7 +140,9 @@ pub(crate) fn lcm_signed_int(x: i64, y: i64) -> Result { let a = x.unsigned_abs(); let b = y.unsigned_abs(); - let gcd = gcd_helper::(a, b)?; + // Use the binary GCD, matching `gcd_signed_int` and avoiding the + // per-iteration division of the Euclidean `gcd_helper`. + let gcd = unsigned_gcd(a, b); // gcd is not zero since both a and b are not zero, so the division is safe. (a / gcd) .checked_mul(b)