Keep a loaded prediction worker ready between keyboard opens - #923
Merged
Merged
Conversation
Closing the keyboard still kills the worker that held the typed text, then starts a fresh one that loads the model and waits. The next open adopts it instead of reloading. The spare expires after two minutes and starts its activity observer only on its first request. Closes #922 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Review follow-up: prove the text-holding worker is dead before the spare starts, prove the observer starts once on the first request, resolve the model once, compare switch keys as a set, and correct the docs on when a later open still loads the model. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Review follow-up: a disabled setting now kills the spare worker directly, and the fake worker liveness check matches the image name so a reused process id cannot fail the test. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #922
Problem
Word prediction reloaded its model on every keyboard open, leaving suggestions blank for about a second each time. Release build measurements: 580 to 980 ms per load, of which 480 to 810 ms is building the ONNX session.
Change
prediction::close()runs when the keyboard closes. It kills and reaps the worker that held the typed text, then starts a fresh worker that loads the model and waits.prediction::stop()now also kills the spare. It still runs when scanning ends, when Word prediction is off and on Retry predictions.No protocol interface or persisted schema changes. The pipe messages are unchanged.
Trade-offs
Validation
All run locally on Windows and passing:
npm run prediction-modelnpm run lintnpm testnpm run buildcargo fmt --manifest-path src-tauri/Cargo.toml --checkcargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warningscargo test --manifest-path src-tauri/Cargo.toml: 569 passedNew tests use sleeping subprocesses as fake workers and inject no input. They cover adoption, the three discard cases, expiry, no spare after a failed worker, and
stop()killing the spare.Not verified: the reopen timing in the running app. The built executable cannot be launched from an unelevated shell here, so step 6 of the native checklist in
docs/word-prediction.mdstill needs a manual run on Windows and macOS.🤖 Generated with Claude Code