Keep dictation responsive during heavy work #16

Merged
kleb merged 3 commits from perf/responsive-ui-workers into main 2026-10-29 07:55:57 +01:00
Owner

Large recordings could still block the renderer during PCM processing or bulk IPC, while history JSON, logging and native startup work could block Electron main even though inference already used workers.

Move audio segmentation/normalization/WAV encoding to a Web Worker connected directly to the AudioWorklet. WAVs over 1 MiB use acknowledged chunks and a staging worker instead of a whole-buffer main-thread copy. A persistence worker keeps the full history, lossless migrations and atomic saves; main/UI keep only the recent 200-entry cache. File logs run in a worker, and the existing 500-entry log view renders only visible rows.

Native hotkeys and dependency checks run in isolated Electron helper processes. Windows paste key injection runs in a worker; Electron-required clipboard/window/permission operations remain on main. Helper loss cancels/drains active capture before blocking, registration/recovery is coalesced, and quit drains startup and persistence. A worker-thread hotkey experiment crashed on teardown and was rejected.

Observed maximum 5 ms heartbeat gaps on Linux x64 / Electron 45.1.0:

Workload Before After
30-minute stereo normalization, renderer 2,041 ms 5.3 ms
50,000-entry history load, main 161 ms 5.5 ms
57.6 MB WAV submission, renderer 71.5 ms 7.8 ms
Same WAV submission, main 48.5 ms 7.5 ms

The normalized/staged WAV hashes match exactly; all expected persisted history and unknown metadata remain. These are smoke observations, not universal latency guarantees. DOM/native OS operations still require their owning threads, and OS/driver/native failures can still cause delays. Windows DLL behavior, macOS accessibility permissions and GPU responsiveness were not runtime-tested.

PERFORMANCE.md documents methods, limits and reproduction. The retained responsiveness harness exercises real sandbox preload/IPC/staging/persistence, with only its inference result stubbed; separate real Tiny inference proof covers AudioWorklet -> processing worker -> native Whisper -> live output/history.

Evidence: responsiveness-evidence.tar.gz
Packaged ASAR smoke after native Tiny readiness and capture cancellation: asar-app-proof.png

Proven with 205 passing tests (1,092 assertions), typecheck, oxlint, ESLint, formatting, Knip, production build, a real native capture/import run with responsive controls, full-app helper crash/concurrent recovery/startup-quit checks, UI keyboard/filter/confirmation flows, and Linux unpacked/ASAR worker-path validation. The virtualizer intentionally opts out of React Compiler for its mutable API; oxlint reports the compatibility warning without failing.

The recovery review finding is fixed: recovery waits for new block tasks and refuses to clear a newer failure. A held-probe/typing-state test killed the real helper, verified the failed attempt retained its cause, and confirmed a fresh retry recovered. Regression proof: dependency-race-regression.json

Large recordings could still block the renderer during PCM processing or bulk IPC, while history JSON, logging and native startup work could block Electron main even though inference already used workers. Move audio segmentation/normalization/WAV encoding to a Web Worker connected directly to the AudioWorklet. WAVs over 1 MiB use acknowledged chunks and a staging worker instead of a whole-buffer main-thread copy. A persistence worker keeps the full history, lossless migrations and atomic saves; main/UI keep only the recent 200-entry cache. File logs run in a worker, and the existing 500-entry log view renders only visible rows. Native hotkeys and dependency checks run in isolated Electron helper processes. Windows paste key injection runs in a worker; Electron-required clipboard/window/permission operations remain on main. Helper loss cancels/drains active capture before blocking, registration/recovery is coalesced, and quit drains startup and persistence. A worker-thread hotkey experiment crashed on teardown and was rejected. Observed maximum 5 ms heartbeat gaps on Linux x64 / Electron 45.1.0: | Workload | Before | After | | --- | ---: | ---: | | 30-minute stereo normalization, renderer | 2,041 ms | 5.3 ms | | 50,000-entry history load, main | 161 ms | 5.5 ms | | 57.6 MB WAV submission, renderer | 71.5 ms | 7.8 ms | | Same WAV submission, main | 48.5 ms | 7.5 ms | The normalized/staged WAV hashes match exactly; all expected persisted history and unknown metadata remain. These are smoke observations, not universal latency guarantees. DOM/native OS operations still require their owning threads, and OS/driver/native failures can still cause delays. Windows DLL behavior, macOS accessibility permissions and GPU responsiveness were not runtime-tested. [PERFORMANCE.md](PERFORMANCE.md#ui-responsiveness) documents methods, limits and reproduction. The retained responsiveness harness exercises real sandbox preload/IPC/staging/persistence, with only its inference result stubbed; separate real Tiny inference proof covers AudioWorklet -> processing worker -> native Whisper -> live output/history. Evidence: [responsiveness-evidence.tar.gz](https://git.kleb.sh/attachments/024d451b-2efb-460b-8d43-f0e7bb953ba0) Packaged ASAR smoke after native Tiny readiness and capture cancellation: ![asar-app-proof.png](https://git.kleb.sh/attachments/ce9eab81-af60-4905-930d-255484bb1524) Proven with 205 passing tests (1,092 assertions), typecheck, oxlint, ESLint, formatting, Knip, production build, a real native capture/import run with responsive controls, full-app helper crash/concurrent recovery/startup-quit checks, UI keyboard/filter/confirmation flows, and Linux unpacked/ASAR worker-path validation. The virtualizer intentionally opts out of React Compiler for its mutable API; oxlint reports the compatibility warning without failing. The recovery review finding is fixed: recovery waits for new block tasks and refuses to clear a newer failure. A held-probe/typing-state test killed the real helper, verified the failed attempt retained its cause, and confirmed a fresh retry recovered. Regression proof: [dependency-race-regression.json](https://git.kleb.sh/attachments/af214d0a-aaef-4613-b232-ed40c7703f20)
Collaborator

kReview review

Verdict: no findings

No specific defects were verified in the reviewed changes.

This review did not check generated or vendored files: ui/bun.lock.

kReview checked only the PR diff, metadata, and supplied repository context at a958585d83. It reports only issues supported by this material.

Estimated cost: ~$0.60 total (1.1M in / 2.5k out); this run ~$0.29 (467.3k in / 954 out) / gpt-6.1-terra.

Run time: 1:15 total; this run 0:29.

<!-- codex-forgejo-review --> <!-- codex-forgejo-review-head:a958585d835984932edcff31b2d955b705860f7b --> <!-- codex-forgejo-review-comparison:v1:4c4fe4df5b79547023b89eed985d762d6b57c937cbb8fd915f9a51bb84a639fd --> ## kReview review **Verdict:** no findings No specific defects were verified in the reviewed changes. _This review did not check generated or vendored files:_ `ui/bun.lock`. _kReview checked only the PR diff, metadata, and supplied repository context at `a958585d83`. It reports only issues supported by this material._ _Estimated cost: ~$0.60 total (1.1M in / 2.5k out); this run ~$0.29 (467.3k in / 954 out) / gpt-6.1-terra._ _Run time: 1:15 total; this run 0:29._ <!-- codex-forgejo-review-state:eyJoZWFkU2hhIjoiYTk1ODU4NWQ4MzU5ODQ5MzJlZGNmZjMxYjJkOTU1YjcwNTg2MGY3YiIsImNvbXBhcmlzb25LZXkiOiJ2MTo0YzRmZTRkZjViNzk1NDcwMjNiODllZWQ5ODVkNzYyZDZiNTdjOTM3Y2JiOGZkOTE1ZjlhNTFiYjg0YTYzOWZkIiwic3VtbWFyeSI6Ik5vIHNwZWNpZmljIGRlZmVjdHMgd2VyZSB2ZXJpZmllZCBpbiB0aGUgcmV2aWV3ZWQgY2hhbmdlcy4iLCJmaW5kaW5ncyI6W10sImN1bXVsYXRpdmVDb3N0Ijp7InVzZCI6MC42MDQ2MTM3LCJpbnB1dFRva2VucyI6MTA3MDQ5MSwib3V0cHV0VG9rZW5zIjoyNDg3LCJtb2RlbCI6ImdwdC02LjEtdGVycmEifSwiY3VtdWxhdGl2ZUR1cmF0aW9uTXMiOjc1MTM5fQ== -->
kleb merged commit 2cc1bead63 into main 2026-10-29 07:55:57 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kleb/VoiceTyper!16
No description provided.