uttrflow / uttrflow/uttrflow-swift

Dictionary learning re-encodes every spoken span for each window-title term

Open
#779 0 comments 0 reactions 0 assignees View on GitHub
area:dictation bug P2 performance
Dominant language
Swift
Stars
4
Forks
17
Avg merge
3h 32m
Merged PRs (30d)
277

Description

## Problem

`LearnableWords.seenAndSaid` builds the spoken spans once but calculates each span's Double Metaphone code again inside the loop over title terms. A long dictation and a title containing many eligible terms multiply the expensive encoding work. This also occupies the personal dictionary actor while learning runs after insertion.

## Evidence

Reviewed main at `8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d`. Reproduced with unchanged repository source in an isolated Swift package on macOS. Checks assert the observed problem, not a completed fix or a full-app test pass.

Release build, five runs per input: 600 spoken words (599 copies of `calibrate`, then one generated proper-name term), and 64 distinct alphabetic title terms (`Zorva` followed by two lowercase letters). This stays within the implementation's 64-title-term bound. Median `seenAndSaid` duration was **915.7 ms**, returning eight matches. A 600-word utterance has 1,797 spans of one to three words, and each title term can re-encode all of them. This is a bounded stress case, not a typical-title benchmark or a measured increase in time before text insertion.

## Relevant code

- [Sources/UttrflowDictionary/LearnableWords.swift:16](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowDictionary/LearnableWords.swift#L16)
- [Sources/UttrflowPipeline/DictationPipeline.swift:555](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowPipeline/DictationPipeline.swift#L555)
- [Sources/UttrflowPipeline/DictationPipeline.swift:788](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowPipeline/DictationPipeline.swift#L788)

## Acceptance criteria

- Prepare each spoken span's phonetic code at most once per learning call and reuse it across title terms. Keep spelling/opening checks and result ordering unchanged.
- Assert identical learned candidates for the existing cases and a long utterance with many title terms.
- Add a work-count check or benchmark showing encoding work grows with the number of spoken spans plus title terms, rather than their product; avoid a fragile wall-clock CI threshold.

## Existing work checked

#221 addresses repeated screen-word encoding in AI `ScreenCandidates`, a different path. #215 concerns repeated dictionary persistence in usage bookkeeping. This issue is redundant phonetic encoding in dictionary learning.

Contributor guide

Open the contributing guide

Research direction

Start in Sources/UttrflowDictionary/LearnableWords.swift at LearnableWords.seenAndSaid, then inspect its callers in Sources/UttrflowPipeline/DictationPipeline.swift around lines 555 and 788. Verify the existing candidate cases and add coverage for a long utterance with many title terms. Done means each spoken span is encoded once per learning call, candidate results and ordering remain unchanged, and a work-count check demonstrates non-product growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.