Skip to content

feat(ios): disambiguate double-letter swipes and speed up path scan - #3138

Merged
kitlangton merged 1 commit into
devfrom
feat/ios-swipe-double-letters-and-fast-scan
Dec 1, 2026
Merged

kitlangton merged 1 commit into
devfrom
feat/ios-swipe-double-letters-and-fast-scan

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Swiping a small loop or lingering on a repeated letter now distinguishes double-letter words like too, off, poll, reed, and feed on iPhone, while cutting swipe decode time by 37%.
Plain fast swipes without loops keep their existing behavior, 240 Hz coalesced sub-frame touches reach the swipe stroke, and 11-column layouts use the drawn character pitch.

❌ Before

  1. SwipeDecoder collapsed consecutive identical keys (k == last) without recording which key repeated, giving "to"/"too", "of"/"off", "pool"/"poll", and "red"/"reed" identical spatial scores; drawing a loop also stretched gesture.length and warped the 32-sample template alignment, while stationary end-key holds before lift were dropped on step <= 1e-4.
  2. KeyboardKeyPlaneView ignored UIEvent.coalescedTouches(for:), clipping 240 Hz sub-frame corners and loops, and KeyboardLayout.swipePitch used 10-column letterWidth on 11-column layouts.
  3. Each swipe ran ~60,000 Set<Int> hash lookups, ~20,000 sqrt calls across candidate scans, and sorted all 1,500 prefiltered candidates when only the top 80 entered aligned scoring.

✅ After

  1. Candidate scans record a 64-bit repeatMasks bitmask; Gesture extracts single-key micro-loops out of raw and preserves stationary corner/end-key holds as RepeatSite markers so matching repeated letters earn repeatBonus without penalizing straight swipes.
  2. KeyboardKeyPlaneView forwards intermediate coalescedTouches into SwipeTyping.recordCoalesced, slidTapLetter checks the top two readings for return-to-start words, and swipePitch uses characterWidth + metrics.gap.
  3. SwipeDecoder precomputes a compact [UInt64] skip bitset (~12.5 KB), a pairwise KeyGrid distance table, hoisted pointer resampling/DTW buffers, and a bounded top-80 shortlist.
- if k == Int(KeyGrid.skip) || k == last { continue } // lost repeated-key identity & stationary lift time
+ if k == last { repMask |= 1 &<< UInt64(vCount - 1); continue }
+ let stripped = SwipeDecoder.extractLoops(fullRaw, arrivals: arrivals, departures: departures)
+ repeatCredit = Self.repeatBonus(vertices, count: m, mask: repeatMasks[c], repeats: gesture.repeats, ...)

📊 Numbers: SwipeBenchmarkTests (560 everyday, collinear pause, double-letter loop/hold, multilingual, and return-to-start swipes on iOS Simulator, Debug build)

Measure Before After
Overall Swipe Top-1 accuracy (560 cases) 90.36% (506 / 560) 97.68% (547 / 560)
Overall Swipe Top-3 strip accuracy 99.46% (557 / 560) 100.00% (560 / 560)
Double-letter loop & key-hold Top-1 (120 cases) 65.00% (78 / 120) 99.17% (119 / 120)
Swipe decode p50 latency (Debug Simulator) 24.02 ms 15.17 ms (-36.8%)
Swipe decode p95 latency (Debug Simulator) 44.58 ms 34.70 ms (-22.2%)
Extra persistent dirty RAM baseline ~12.5 KB [UInt64] skip bitset

The new tests in SwipeDecoderTests and SwipeBenchmarkTests fail without the change; all 1,049 unit tests pass.

👀 Read: extractLoops and appendDwellRepeats in SwipeDecoder.swift (interior holds require a >= 30° corner so straight-through pauses like r in tired and u in put keep their single-letter disambiguation role). The rest is buffer and touch plumbing.

🔍 Found in a swipe path-matching audit · measured with deterministic SwipeBenchmarkTests on iOS Simulator

Checks run
  • python3 scripts/code-shape.py --check: pass
  • xcodebuild test -project HEXMobile.xcodeproj -scheme HEXMobile: 1,049 executed, 0 failures

@kitlangton
kitlangton force-pushed the feat/ios-swipe-double-letters-and-fast-scan branch from 8dd61e0 to e697a8a Compare December 1, 2026 05:45
@kitlangton
kitlangton merged commit 08ab238 into dev Dec 1, 2026
1 check passed
@kitlangton
kitlangton deleted the feat/ios-swipe-double-letters-and-fast-scan branch December 1, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant