From 17af33579ff4ef25c58ae97e16cfb3cb50fc0aa7 Mon Sep 17 00:00:00 2001 From: Ryan Vogel <89211796+R44VC0RP@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:10:12 -0500 Subject: [PATCH] iOS keyboard: Adaptive touch's guard takes the next reading the baseline clears, not a second search When a personal reading doesn't clear the baseline margin, the guard used to run a whole second decode with the baseline centres to find their own decision. On the public benchmark that happened on ~5% of checked letters and cost ~0.13 ms each, pushing the simulator's English per-letter p95 up to +0.1-0.16 ms. Now it takes the next of the personal readings that the baseline centres also clear by the margin (TypingDecoder.replaces, mostly without a search), or none: still never a rewrite the keyboard wouldn't make with the Experiment off. Only a two-word reading, which replaces can't score, still asks the baseline decode. Verified: xcodebuild test on the iPhone 17 simulator (iOS 27.2) on 8c93f6f5: 461 tests, 0 failures (1 skipped, existing). Held-out benchmark on the same simulator, profile learned on the 300 dev sentences: WER unchanged by this (EN 5.24% -> 5.16%, ES 8.34% -> 8.26%); per-letter engine p95 against Experiment off, two runs each: EN -0.09 / +0.02 ms, ES -0.01 / +0.04 ms; peak footprint -0.11 / +0.00 MB. --- .../FullKeyboard/AutocorrectEngine.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ios/HEXShared/FullKeyboard/AutocorrectEngine.swift b/ios/HEXShared/FullKeyboard/AutocorrectEngine.swift index 149865db6..87fd42d50 100644 --- a/ios/HEXShared/FullKeyboard/AutocorrectEngine.swift +++ b/ios/HEXShared/FullKeyboard/AutocorrectEngine.swift @@ -919,9 +919,21 @@ final class AutocorrectEngine { || properNoun(for: token) != nil let previous = Self.previousWord(before, token: token) var decision = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: keys) - if let baseline = decoderBaselineKeys, let replacement = decision?.replacement, - decoder.replaces(with: replacement, taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline) != true { - decision?.replacement = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline)?.replacement + if let baseline = decoderBaselineKeys, let replacement = decision?.replacement { + func clears(_ reading: String) -> Bool? { + decoder.replaces(with: reading, taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline) + } + switch clears(replacement) { + case true?: + break + case false?: + // The next reading the baseline would also put in, if any: never a new rewrite, + // and no second search on the letter. + let readings = decision?.readings ?? [] + decision?.replacement = readings.lazy.map(\.text).first { $0 != replacement && clears($0) == true } + case nil: + decision?.replacement = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline)?.replacement + } } decoderCache = (before, taps, decision) return decision