Open Bug 2052369 Opened 1 month ago Updated 15 days ago

Smart Window perf: eliminate per-keystroke full-doc work in the smartbar / multiline editor

Categories

(Core :: Machine Learning: Frontend, defect)

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 dispatchTransaction reads the value before the "document changed" guard.
  • hasMention traverses the whole document on every keystroke.
  • #posFromTextOffset walks the document up to three times per selection update.
  • The keyup handler _on_keyup is 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).

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.

Component: Address Bar → Machine Learning: Frontend
Product: Firefox → Core
Whiteboard: [genai] → [aiasst]

bug 2017939 added hasMention
bug 2003063 posFromText and dispatchTransaction

@flozia can provide some context

Depends on: 2017939, 2003063
You need to log in before you can comment on or make changes to this bug.