From db1c69e61bc4d49e18ceadf8d1a3cd38eb4d1080 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 28 Aug 2026 19:37:01 +0200 Subject: [PATCH] join: skip locale comparison in check_order default mode In the default check-order mode the ordering warning is only emitted once unpaired lines have been seen (has_unpaired=true). Calling input.compare() (which may invoke ICU locale_cmp) on every line regardless was wasteful: on a 1M-line file with a locale active this accounts for ~35% of the total runtime. Early-return before the compare() call when the result cannot possibly trigger a warning. Benchmarks (fr_FR.UTF-8, 1M lines): Before: 814 ms (1.90x slower than GNU join) After: 523 ms (1.25x slower than GNU join) --- src/uu/join/src/join.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 2cf4368a88..1126ed64aa 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -630,6 +630,13 @@ impl<'a> State<'a> { return Ok(Some(line)); } + // In Default mode the warning is only emitted when there are + // already unpaired lines, so skip the (potentially expensive) + // locale comparison on every line when no violation is possible yet. + if input.check_order == CheckOrder::Default && (!self.has_unpaired || self.has_failed) { + return Ok(Some(line)); + } + let diff = input.compare(self.get_current_key(), line.get_field(self.key)); if diff == Ordering::Greater