Add timeline markers to trace document.write calls

NEW
Unassigned

Status

P3
normal
4 years ago
4 months ago

People

(Reporter: fitzgen, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [devtools-platform])

document.write messes up all kinds of stuff and stops all kinds of pipelining. We should trace it and surface it in the perf timeline.
(In reply to Nick Fitzgerald [:fitzgen] from comment #0)
> document.write messes up all kinds of stuff and stops all kinds of
> pipelining. We should trace it and surface it in the perf timeline.

There are really three cases:

 1) Any non-async, non-defer script *might* call document.write, so even if it's not called, there's some complexity involved in order to prepare for the *possibility*. I suppose you could try to measure the overhead of a non-async script vs. an async script for parsing purposes, but I expect the overhead to be negligible and not worth bothering Web devs about.

 2) A script (has to be non-async, non-defer) calls document.write (potentially multiple times) and the calls taken together end up writing a balanced subtree. In this case, the only perf badness is that the parsing happens on the main thread and can't be overlapped with the main thread on a different CPU core. Unclear if this is worth bothering Web devs about.

 3) The document.writes are not balanced. Look for nsContentUtils::ReportToConsole after "if (speculationFailed) {" in nsHtml5StreamParser::ContinueAfterScripts. This is worth whining about for sure. (Already whined to console.) I suppose you could report how much wall clock time the parser thread used for work that got thrown away, but that doesn't fit a timeline, since it's overlapped with the main thread.
What if we just trace the initial HTML parsing if it happens on the main thread, and since markers can have arbitrary metadata, we attach a why-we-parsed-html-on-the-main-thread string?
Flags: needinfo?(hsivonen)
Summary: Add timeline markers to trace document.write calls → [marker] Add timeline markers to trace document.write calls
(In reply to Nick Fitzgerald [:fitzgen] from comment #2)
> What if we just trace the initial HTML parsing if it happens on the main
> thread, and since markers can have arbitrary metadata, we attach a
> why-we-parsed-html-on-the-main-thread string?

The question seems to assume parser behaviors that are not there.

Markup that came from the network/file channel is parsed off-the-main thread. If there are bad (case #3 in my previous comment) document.writes, markup from the network/file channel that is logically after the script that made the bad document.write call(s) is parsed again (and again if there are yet more bad document.writes later).

Markup that came from strings passed to document.write is always parsed on the main thread.

In both cases, the parser outputs a sequence of operations to be performed in order to construct the DOM and those operations are performed on the main thread.

So you can put DOM construction and document.write parsing in the main-thread timeline. Additionally, if there are bad document.writes, you could attach info about how much off-the-main-thread waste that particular document.write caused (by reporting the time the parser thread spent such that the work was thrown away).
Flags: needinfo?(hsivonen)

Updated

4 years ago
Whiteboard: [devtools-platform]
Triaging. Filter on ADRENOCORTICOTROPIC (yes).
OS: Mac OS X → Unspecified
Priority: -- → P3
Hardware: x86 → Unspecified
Summary: [marker] Add timeline markers to trace document.write calls → Add timeline markers to trace document.write calls

Updated

7 months ago
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.