Closed Bug 1766954 Opened 2 years ago Closed 2 years ago

[CTW] Poor performance caching large text nodes

Categories

(Core :: Disability Access APIs, defect)

defect

Tracking

()

RESOLVED FIXED
102 Branch
Tracking Status
firefox102 --- fixed

People

(Reporter: Jamie, Assigned: Jamie)

References

Details

Attachments

(1 file)

STR:

  1. Enable CTW and restart Firefox.
  2. Open this test case:
    data:text/html,<pre id="pre"></pre><script>let text = ""; for (let i = 0; i < 10000; ++i) { text += "this is a line of text\n"; } pre.textContent = text;</script>
    • Expected: Content process blocks for several seconds.
    • Actual: Content process should block for a fraction of a second.

This will happen whenever a user is loading large plain text files such as logs. I hit this myself loading a raw log from Treeherder.

Profile: https://share.firefox.dev/3vrAsBQ

This occurs when we're caching line start offsets. We spend a lot of time in nsTextFrame::GetRenderedText, which we use to convert between rendered and content offsets. I guess GetRenderedText has to do a linear walk, and because this text is so long, that is rather problematic.

It seems to me that the only kind of text node that is likely to be this long is pre-formatted text. In that case, the rendered offsets should be the same as the content offsets. Perhaps we can avoid calling GetRenderedText in this case. We should be able to detect that with frame->StyleText()->WhiteSpaceOrNewlineIsSignificant(), though we may need NewlineIsSignificant(frame) as well; I'm not sure.

Assignee: nobody → jteh

For pre-formatted text, the content text and rendered text are the same.
Therefore, there's no point calling nsIFrame::RenderedText, which is quite slow for nodes containing a large chunk of text.
This improves performance significantly when caching line start offsets for large plain text files such as logs.

Pushed by jteh@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4e3e696ff054
TextLeafRange: Don't call nsIFrame::RenderedText for pre-formatted text. r=eeejay
Pushed by jteh@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a62abba5bf3d
TextLeafRange: Don't call nsIFrame::RenderedText for pre-formatted text. r=eeejay
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
Flags: needinfo?(jteh)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: