Smart Window perf: eliminate per-keystroke full-doc work in the smartbar / multiline editor
Categories
(Core :: Machine Learning: Frontend, defect)
Tracking
()
People
(Reporter: thasan, Unassigned)
References
(Blocks 1 open bug)
Details
(Keywords: perf, Whiteboard: [aiasst])
While a user composes a prompt, several operations do work proportional to the whole document on every keystroke, which is visible jank on slower CPUs.
- The multiline editor's value getter serializes the entire ProseMirror document, and the input handler reads it more than once per keystroke. Serialization also happens for caret and selection changes, because
dispatchTransactionreads the value before the "document changed" guard. hasMentiontraverses the whole document on every keystroke.#posFromTextOffsetwalks the document up to three times per selection update.- The keyup handler
_on_keyupis async, allocating a microtask per key release. - Most significantly, the input handler unconditionally issues a full address-bar provider query through
startQuery; during pre-send composition this runs undebounced on every keystroke, and the in-progress prompt text is pushed through the provider path.
AI Suggested fix. Memoize the serialized value by document identity and read it once; move the value read inside the "document changed" guard; track mention presence as plugin state; resolve selection offsets in a single walk; make the keyup handler synchronous; and debounce the provider query, suppressing it entirely during pre-send composition so the prompt text does not leak into providers.
Searchfox references for the code this bug touches. These are drift-proof path-scoped searches (line numbers in the description track the local tree and may drift against mozilla-central tip; the symbol is the durable anchor).
- MultilineEditor value getter / #dispatchTransaction: https://searchfox.org/mozilla-central/search?q=dispatchTransaction&path=multiline-editor.mjs
- #posFromTextOffset: https://searchfox.org/mozilla-central/search?q=posFromTextOffset&path=multiline-editor.mjs
- hasMention: https://searchfox.org/mozilla-central/search?q=hasMention&path=MentionsPlugin.mjs
- _on_input / startQuery (undebounced): https://searchfox.org/mozilla-central/search?q=startQuery&path=SmartbarInput.mjs
- _on_keyup: https://searchfox.org/mozilla-central/search?q=_on_keyup&path=SmartbarInput.mjs
Comment 2•25 days ago
|
||
Most significantly, the input handler unconditionally issues a full address-bar provider query through startQuery; during pre-send composition this runs undebounced on every keystroke, and the in-progress prompt text is pushed through the provider path.
The address bar doesn't run every keystroke through startQuery. There is a short delay after each keystroke before the query is executed, that is if you are hooking up as a provider. If you are hooking up as a provider, then it would be every keystroke.
This bug probably needs breaking down into multiple pieces which are looked at individually, as there seems to be different parts in play here - the multiline editor, the smart bar and the mentions.
Moving across to Machine Learning: Frontend, as this seems to be in the responsibility of the smart window team rather than the urlbar team.
Updated•18 days ago
|
Updated•18 days ago
|
Comment 3•15 days ago
|
||
bug 2017939 added hasMention
bug 2003063 posFromText and dispatchTransaction
@flozia can provide some context
Description
•