DescriptionMake the HTMLDocumentParser yield more aggressively
Depends on:
https://codereview.chromium.org/302063002/
When the BackgroundHTMLParser finishes a chunk of tokens
it posts a task to the main thread for tree-building.
Because the Chromium MessageQueue is a FIFO,
if the BackgroundHTMLParser schedules 10
chunks in a row (which it does) the main thread will
process all 10 chunks in a row before handling other work
sitting in the message queue (like RAF callbacks) while we
happily miss (possibly many) frames.
To fix this, I've made the HTMLDocumentParser only
take the chunk from the background parser in
didReceiveParsedChunkFromBackgroundParser
and save the chunk (as it already knew how to do
for the "speculations" code path), preload all
the resources in that chunk, and then post a second
task to actually do the processing (after any scheduled
work). This has the effect of taking 10 chunks which
came in in a row and only processing them 1 at a time.
This will incur one extra round-trip through the
MessageLoop per chunk (which should be tiny compared
to the cost of mallocing all the nodes
represented by the chunk, etc), but will make it so
that the parser never processes more than one chunk
while we're waiting on other work.
I've also lowered the max-processing time from 500ms
to 8ms (we might want to go lower) to make the parser
yield more aggressively to RAF, etc.
I anticipate that this change may slow down
page load time numbers on Desktop Chrome (by a tiny percent)
and should increase responsiveness on mobile.
I created a pathological test case:
http://jsbin.com/nitobiru/35
Which repeatedly parses 10k divs while trying to keep to
60hz with RAF. (It uses the newly-landed async srcdoc
support to drive the parser in the background.)
That test is pathological due to crbug.com/365919, but even
working around that bug with http://jsbin.com/nitobiru/38
it still only hits 26 fps or so. Without that workaround /35
hits only 4fps.
Sending all chunks down the deferred work code-path
brought things up to 20fps, limiting the parser to only 8ms of
work at a time brought behavior to about 35fps on my linux desktop.
I believe that the async srcdoc work from bug 308321 combined with
this patch, now provides a viable option for sites to do async HTML
parsing with much lower risk of jank.
I also expect that this may improve Speed Index scores on both
desktop and devices as we're more aggressive about feeding
the preloader after this change (previously we would not issue
preload requests if we were about to process the tokens in that call).
BUG=356292
Patch Set 1 #
Total comments: 6
Patch Set 2 : Removed chunk size changes #
Total comments: 1
Messages
Total messages: 26 (2 generated)
|