Open Bug 1912069 Opened 3 months ago Updated 3 months ago

Testcase takes 22s to copy-paste from browser to a text editor. With a tiny modification, it takes 200ms.

Categories

(Core :: Web Painting, enhancement)

enhancement

Tracking

()

People

(Reporter: mayankleoboy1, Unassigned)

References

Details

Attachments

(3 files)

Attached file testcase_slow.html
  1. Type the following in a new tab : " data:text/html, <html style contenteditable spellcheck="false"> " . This will create a text editor type thingy.
  2. Open the slow testcase in the browser
  3. Select all the text and copy it (Ctrl+A, Ctrl + C)
  4. Paste the text into the text-editor from #1
  5. Now repeat the steps with the fast testcase

Fast: https://share.firefox.dev/4fDxgIg (174ms)
Slow: https://share.firefox.dev/4daAYaT (22s)

The fast testcase is the original testcase. To make it slow, I deleted all the <div> and </div> tags.

Maybe something to improve for the slow testcase?

Attached file testcase_fast.html
Attached file about:support

:jjaschke, I am ni? you as you may have some opinion on this.

Flags: needinfo?(jjaschke)

Interesting case, thank you for posting. The 'slow' case is a node with a lot of child nodes, hence ComputeIndexOf() becomes slow and shows up in the profile. I wrote some technical details in Bug 1503581 comment 14.

Since I have looking into bug 1503581, I tried this test case with that WIP patch applied. It turns out that said patch adds roughly one order of magnitude to the slow case (the fast testcase stays the same. It doesn't use the cache because of the 1k child node threshold). The reason is, that while pasting, the document's generation changes permanently, forcing the cache to be rebuilt constantly.

I think it may be possible to add some batching there:
While inserting, we're only adding nodes into a single parent node. So, theoretically, we don't have to clear the cache (this is more a question than a statement!). Note that I have limited knowledge of the Editor internals.
If we would add batching to the AutoPlaceholderBatch which would clear the cache once and then prohibit clearing the cache, we would keep the cache alive during the paste operation.
I gave that a try, and the slow test case was about as fast as the fast one (<1s).

However, IIUC inserting nodes during paste could trigger DOM mutations, which would currently be handled during paste. These would have to be batched as well.

Masayuki, what do you think about this (also bug 1503581)? I'm sure I've missed many edge cases and I don't know if AutoPlaceholderBatch is the right place to add the batching. Do you think it makes sense to look deeper into this?

Flags: needinfo?(jjaschke) → needinfo?(masayuki)
See Also: → 1911452
See Also: → 1909171

Well, I think it's fine to put it into HTMLEditor::HTMLWithContextInserter::InsertContents because the insertion occur sequentially. It might break some cases if legacy mutation event listeners intercepts something. However, in such tricky case, web apps should charge with the result by themselves. (FYI: Chrome/Safari does not dispatch events while their builtin editor touches the DOM.)

Flags: needinfo?(masayuki)
See Also: → 1913253
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: