Repository navigation
Add explainer for deferrable model installation #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reillyeon
wants to merge
2
commits into
main
Choose a base branch
from
deferrable-install-explainer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Explainer: Deferrable Web Speech API Model Installation | ||
|
|
||
| ## Introduction | ||
|
|
||
| On-device speech recognition via the Web Speech API requires machine learning speech models to be downloaded and installed locally before processing audio. These models typically range from tens to hundreds of megabytes in size. | ||
|
|
||
| Currently, developers can use `SpeechRecognition.install()` to trigger an immediate download, similar to a file download or `fetch()` request. When invoked during active user sessions—such as an ongoing WebRTC video conference—a high-bandwidth download can compete with real-time network traffic, leading to audio/video stuttering and reduced media quality. Immediate downloads also risk impacting end-user networks if they can be triggered in a coordinated manner, such as an application everyone launches when they get to work at 9 o’clock. | ||
|
|
||
| This explainer proposes adding a new `downloadPriority` hint to `SpeechRecognitionOptions` to allow sites to express whether they instead need the model to be available as soon as possible (`"immediate"`) because model availability blocks a critical user journey or whether it is okay for the feature to be available later (`"deferrable"`). Deferrable installation allows the browser to complete the download more slowly or during idle time, leveraging the same mechanisms used for browser updates to reduce its impact. | ||
|
|
||
| ## User Needs & Goals | ||
|
|
||
| ### User Need | ||
|
|
||
| Users expect real-time web applications (e.g., video calling, live streaming) to remain smooth and responsive. Unintended high-bandwidth network activity during an active session degrades media quality, particularly on constrained or low-bandwidth connections. | ||
|
|
||
| ### Developer Need | ||
|
|
||
| Developers want to offer fast, private, on-device features, but need a safe way to prepare on-device assets opportunistically. When a fallback capability (such as cloud-based speech recognition) is available, developers can request background downloads to avoid network contention. Conversely, developers need to be able to express when on-device processing blocks a critical user journey and it is therefore worth elevating the priority of the download to that of a typical user-initiated file download. | ||
|
|
||
| ### Goals | ||
|
|
||
| * Enable developers to express that the deferrable download model is compatible with their desired user experience. | ||
| * Provide an explicit `"immediate"` hint for when model availability blocks a critical user journey. | ||
|
|
||
| ### Non-Goals | ||
|
|
||
| * Guaranteeing exact completion times or strict scheduling guarantees for downloads. | ||
|
|
||
| ## Proposed API Design | ||
|
|
||
| We propose adding a `downloadPriority` hint to the options dictionary passed to `install()` (extending `SpeechRecognitionOptions`), defaulting to `"immediate"` to maintain the current default behavior: | ||
|
|
||
| ``` | ||
| enum SpeechRecognitionDownloadPriority { | ||
| "immediate", | ||
| "deferrable", | ||
| }; | ||
|
|
||
| dictionary SpeechRecognitionInstallOptions : SpeechRecognitionOptions { | ||
| SpeechRecognitionDownloadPriority downloadPriority = "immediate"; | ||
| }; | ||
|
|
||
| partial interface SpeechRecognition { | ||
| static Promise<undefined> install(SpeechRecognitionInstallOptions options); | ||
| }; | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| This example illustrates initiating a deferrable model installation in the background while immediately falling back to cloud-based speech recognition: | ||
|
|
||
| ```javascript | ||
| // Trigger deferrable model download in background. | ||
| SpeechRecognition.install({ downloadPriority: "deferrable" }).catch(err => { | ||
| console.warn("Background model download failed:", err); | ||
| }); | ||
|
|
||
| // Continue with speech recognition immediately without waiting. | ||
| const recognition = new SpeechRecognition(); | ||
| recognition.start(); | ||
| ``` | ||
|
|
||
| ## Detailed Design Considerations | ||
|
|
||
| ### Browser Download Scheduling | ||
|
|
||
| Browsers already possess infrastructure to handle deferred, low-priority downloads (such as component updates and system updates) in order to avoid the scenarios listed above. | ||
|
|
||
| When `downloadPriority` is set to `"deferrable"`: | ||
|
|
||
| * The download state for the origin is unmasked upfront. Therefore if the model is already available, `install({ downloadPriority: "deferrable" })` will resolve immediately. | ||
| * Downloading may automatically pause while the browser is in use and resume when idle. | ||
| * The browser may delegate downloads to the underlying system’s networking service to pick a time when the system as a whole is idle. | ||
| * Promise resolution continues to operate normally, though no progress may be made until conditions permit downloading. | ||
|
reillyeon marked this conversation as resolved.
Resolved
|
||
| * A later call to `install({ downloadPriority: "immediate" })` overrides this request and begins an immediate download. | ||
|
|
||
| Since deferrable downloads may be significantly delayed in starting and finishing they should survive tab closure. In future sessions the developer will either observe `SpeechRecognition.availability()` return `"downloading"` or `"available"` depending on whether the install is complete. | ||
|
|
||
| ### Immediate Downloads | ||
|
|
||
| When `downloadPriority` is set to `"immediate"` (the default) the browser treats the download request as a typical resource load or file download. This preserves expected behavior for interactive flows where the user is actively waiting for a local model to complete installation before continuing. If the page is closed before the download completes the download priority could be reduced so that the model is available in a future user session but is no longer a priority. | ||
|
|
||
| ## Alternate Designs | ||
|
|
||
| ### Alternative 1: Deferrable downloads by default | ||
|
|
||
| **Description:** Change the default behavior and require developers to explicitly choose immediate downloads. | ||
|
|
||
| **Why Rejected:** While this option makes mitigating the concerns of immediate downloads the default behavior, it is a breaking change to existing developer expectations as `install()` with no priority option would now rarely resolve during the current session. By default, a Web API should not return a Promise that may never resolve during the user's session without giving the developer progress or scheduling visibility. When a site calls `install()` without specifying a priority, the browser should fulfill that request immediately like any standard network fetch, rather than silently deferring it to an unknown future idle window. | ||
|
|
||
| ### Alternative 2: Triggering installs on page unload | ||
|
|
||
| **Description:** Having applications wait until they are idle or the user is about to navigate away before calling `install()`. | ||
|
|
||
| **Why Rejected:** Unreliable. Users frequently close browser tabs or windows directly, which doesn’t give the page time to call `install()`. An explicit API parameter allows the browser to manage the download lifetime across tab closure or background states cleanly. | ||
|
reillyeon marked this conversation as resolved.
Resolved
|
||
|
|
||
| ## Security Considerations | ||
|
|
||
| The background scheduling and priority do not alter the origin sandbox model or grant new access to system resources. Origin-based capability masking remains enforced to prevent untrusted cross-origin access to installed models. | ||
|
|
||
| ## Privacy Considerations | ||
|
|
||
| The download masking technique is unmodified, so a site still needs to call `install()` with user activation to unmask the model download state. There is a potential minor benefit in the transition between `"downloading"` and `"available"` states now likely occurring when there isn't a page context around to observe it. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.