Repository navigation
Keep lf-suggestion's word emphasis in two shared highlights each suggestion edits - #5723
Conversation
…estion edits Each suggestion's emphasize, settle and disconnect rebuilt both CSS highlights from every suggestion's ranges, so upgrading, deciding or removing N suggestions copied about N² ranges. The two Highlights are now created once; a suggestion adds and deletes only its own ranges. What the page paints is unchanged. Refs #5722
|
@leaf-agent The JavaScript rebuild is gone, but
|
…emoval The first commit deleted each leaving range from the shared highlights. Firefox walks a highlight's list to delete a range, so removing every suggestion from a page took 5.3 s of Highlight calls at 800 suggestions, against 0.64 s for the rebuild it replaced. Adds made as each suggestion upgraded also grew with the highlight there. Ranges now arrive and leave through two pending sets applied in one microtask: a removal rebuilds each highlight once from the ranges it keeps, as lf-text-document.js's unpaint does. Measured inside Highlight's methods at 200/400/800 suggestions, Firefox's upgrade takes 9/16/29 ms and removing them all 0–2 ms. Refs #5722
|
You were right: the first commit made Firefox worse. Removing 800 suggestions spent 5.3 s inside To isolate the highlight work I wrapped
The description now carries the full table, and its performance claim is scoped to the highlight calls. The rest of disconnect still grows faster than linearly: removing every suggestion takes 2.4 s at 400 in Chromium, with or without emphasis. This PR doesn't address that, and I haven't traced it. |
Changing one suggestion's word emphasis (its upgrade, its decision or its removal) rebuilt both
lf-sug-delandlf-sug-inshighlights from every suggestion's ranges, so upgrading, replaying or removing N suggestions cost about N² range copies. The twoHighlights are now registered once, under the same names and priority. A suggestion's ranges are queued to arrive or leave, and a microtask applies them at the end of the task, before the next frame. A removal rebuilds each highlight once from the ranges it keeps, aslf-text-document.js'sunpaintdoes, because Firefox walks a highlight's list to delete each range. Adding ranges one suggestion at a time as they upgraded also grew with the highlight's size in Firefox. What the page paints is unchanged.Measured as time spent inside
Highlight's constructor,add,delete,clearand iterator, on a page of N rewrites (six ranges each), with a throwaway test that isn't committed. "Remove all" removes every suggestion in one task.A single decision now costs one rebuild of the highlights it touches, which is linear in the page's emphasis ranges (Firefox's per-range delete was no cheaper).
leaf-dev bench's generated page has no suggestions, so the bench doesn't cover this path.The rest of disconnect is untouched. With or without emphasis, removing every suggestion takes 0.2 s at 100 suggestions and 2.4 s at 400 in Chromium (Firefox is similar), so that path also grows faster than linearly. I haven't traced which part does; the margin contribution's
unregisteris the obvious candidate.Verification:
tests/browser/widgets/test_suggestions.py,test_suggestion_emphasis_skips_generated_interface_between_changed_words,test_a_second_tab_takes_the_decision_back_too,pnpm run checkand pre-commit pass.This fixes item 1 of #5722.
obligationsIn,lf-toc's measuring and Page Map search use other code paths and stay open there.Refs #5722 — automated triage