Open Bug 1515353 Opened 6 years ago Updated 9 months ago

Create text node buffers on the HTML parser thread (and check Latin1 and bidi there)

Categories

(Core :: DOM: HTML Parser, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: hsivonen, Unassigned)

Details

Currently, the HTML parser sends text node content as UTF-16 to the main thread and the main thread checks the data to see if it's Latin1-only and to see if it has right-to-left characters and shrinks the text node in the Latin1 case. We could do the checks and the Latin1 shrinking on the HTML parser thread in order not to have to do those tasks from the main-thread event loop.
Priority: -- → P3
Severity: normal → S3

I measured time spent in SetText as a proportion of the time spent with nsHtml5AutoFlush live.

For ad iframes and some background documents from Web Extensions, the time spent is negligible.

Other than that, the time spent seems to vary from 2% (Amazon front page) to 16% (HTML spec on Android) with app-like pages landing in the low end of that range and document-like pages landing from middle to high end of that range.

The time the HTML parser spends building the DOM on the main thread is tiny in comparison to the time spent in layout. In that sense, one might argue against putting effort into parser optimizations. However, we have mechanisms to avoid nsHtml5TreeOpExecutor::RunFlushLoop occupying the main thread: We have time-based yielding and pending user event-based yielding to the event loop (since last century, I believe) and we have de-prioritization of background pages (since 2012).

Both predate current hardware and Fission, but if we believe that these mechanisms to avoid nsHtml5TreeOpExecutor::RunFlushLoop occupying the main thread continue to be worthwhile, it should be worthwhile to reduce that time by 2% to 16%.

To get the measured benefit, we should not only move the Latin1 and bidi checks to the parser thread but we should allocate and fill the text buffer for the text node on the parser thread in a form that can be adopted into the text node.

The main complication is that our text nodes have the optimization that the buffer of a whitespace-only text node can be shared with other text nodes that happen to contain the same whitespace. Some of this consolidation computation would have to continue to happen on the main thread if we want to continue to have this memory optimization more broadly than only across the parser thread-created text nodes.

Summary: Check text nodes for Latin1 and bidi on the HTML parser thread → Create text node buffers on the HTML parser thread (and check Latin1 and bidi there)
You need to log in before you can comment on or make changes to this bug.