Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1477)

Issue 258013009: Make the HTMLDocumentParser yield more aggressively

Created:
6 years, 7 months ago by eseidel
Modified:
5 years, 11 months ago
Reviewers:
Sami, abarth-chromium
CC:
blink-reviews, dglazkov+blink, adamk+blink_chromium.org, Sami, alex clarke (OOO till 29th)
Visibility:
Public.

Description

Make 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
Unified diffs Side-by-side diffs Delta from patch set Stats (+17 lines, -17 lines) Patch
M Source/core/html/parser/HTMLDocumentParser.cpp View 3 chunks +11 lines, -17 lines 1 comment Download
M Source/core/html/parser/HTMLParserScheduler.cpp View 1 chunk +6 lines, -0 lines 0 comments Download

Messages

Total messages: 26 (2 generated)
eseidel
6 years, 7 months ago (2014-04-29 00:21:37 UTC) #1
eseidel
https://codereview.chromium.org/258013009/diff/1/Source/core/html/parser/BackgroundHTMLParser.cpp File Source/core/html/parser/BackgroundHTMLParser.cpp (left): https://codereview.chromium.org/258013009/diff/1/Source/core/html/parser/BackgroundHTMLParser.cpp#oldcode48 Source/core/html/parser/BackgroundHTMLParser.cpp:48: static const size_t outstandingTokenLimit = 10000; I didn't mean ...
6 years, 7 months ago (2014-04-29 00:23:12 UTC) #2
eseidel
https://codereview.chromium.org/258013009/diff/1/Source/core/html/parser/BackgroundHTMLParser.cpp File Source/core/html/parser/BackgroundHTMLParser.cpp (left): https://codereview.chromium.org/258013009/diff/1/Source/core/html/parser/BackgroundHTMLParser.cpp#oldcode48 Source/core/html/parser/BackgroundHTMLParser.cpp:48: static const size_t outstandingTokenLimit = 10000; On 2014/04/29 00:23:13, ...
6 years, 7 months ago (2014-04-29 00:24:11 UTC) #3
tonyg
This is both potentially very exciting and scary. This behavior is subtle and not well ...
6 years, 7 months ago (2014-04-29 00:49:51 UTC) #4
eseidel
This change is 3 pieces. I only intended to include 3 (not the chunk-size change). ...
6 years, 7 months ago (2014-04-29 01:12:42 UTC) #5
eseidel
Sorry, I meant only 2. I only intended to change: 1. always take the speculations ...
6 years, 7 months ago (2014-04-29 01:16:16 UTC) #6
Pat Meenan
On 2014/04/29 01:16:16, eseidel wrote: > Sorry, I meant only 2. > > I only ...
6 years, 7 months ago (2014-04-29 12:55:17 UTC) #7
eseidel
I've removed the chunk-size changes (which I had not intended to include). I could also ...
6 years, 7 months ago (2014-04-29 18:24:38 UTC) #8
abarth-chromium
Code change LGTM. I'll let you negotiate with the speed team about how to do ...
6 years, 7 months ago (2014-04-29 18:28:58 UTC) #9
eseidel
I completely agree with the scheduler comments. I'm working on a design doc.
6 years, 7 months ago (2014-04-29 18:29:58 UTC) #10
eseidel
m_speculations are still speculatively decoded chunks. We could still reject them if a chunk happens ...
6 years, 7 months ago (2014-04-29 18:32:02 UTC) #11
eseidel
The CQ bit was checked by eseidel@chromium.org
6 years, 7 months ago (2014-04-29 18:32:11 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/eseidel@chromium.org/258013009/20001
6 years, 7 months ago (2014-04-29 18:33:12 UTC) #13
commit-bot: I haz the power
The CQ bit was unchecked by commit-bot@chromium.org
6 years, 7 months ago (2014-04-29 18:55:30 UTC) #14
commit-bot: I haz the power
Try jobs failed on following builders: mac_blink_rel on tryserver.blink
6 years, 7 months ago (2014-04-29 18:55:31 UTC) #15
abarth-chromium
lgtm
6 years, 7 months ago (2014-04-29 19:33:55 UTC) #16
eseidel
Looks like I will need to either remove the preloader changes, or figure out why ...
6 years, 7 months ago (2014-04-29 19:52:46 UTC) #17
ojan
FWIW, WRT scaling back the constants, I'd vote for trying the most aggressive thing (i.e. ...
6 years, 7 months ago (2014-04-29 22:41:57 UTC) #18
eseidel
We could probably salvage this CL. This is about making the HTMLParser be a better ...
6 years, 4 months ago (2014-08-22 16:31:38 UTC) #19
kouhei (in TOK)
On 2014/08/22 16:31:38, eseidel wrote: > We could probably salvage this CL. This is about ...
6 years, 4 months ago (2014-08-24 01:46:40 UTC) #20
eseidel
For context, we decided the preloader was not ready for prime-time. The result was that ...
6 years, 4 months ago (2014-08-24 03:53:58 UTC) #21
kouhei (in TOK)
I rebased this patch on to ToT and tested on PerformanceTests/Parser/html-parser-threaded.html. This seems to regresses ...
6 years, 3 months ago (2014-09-02 19:09:25 UTC) #22
eseidel
I'm not surprised that it woudl regress pure-parser performance. I'm not sure that's bad. We ...
6 years, 3 months ago (2014-09-02 19:17:16 UTC) #23
Sami
6 years, 3 months ago (2014-09-03 10:43:28 UTC) #25
https://codereview.chromium.org/258013009/diff/20001/Source/core/html/parser/...
File Source/core/html/parser/HTMLDocumentParser.cpp (right):

https://codereview.chromium.org/258013009/diff/20001/Source/core/html/parser/...
Source/core/html/parser/HTMLDocumentParser.cpp:497: while
(!m_speculations.isEmpty()) {
No need to add it into this patch, but let me just point out a function in the
scheduler which may be useful here: Scheduler::shouldYieldForHighPriorityWork().
Eventually it will get replaced with proper "idle" task support, but for the
time being checking whether we should yield in this loop might be worth trying.
It may allow you to use a higher time limit too.

Powered by Google App Engine
This is Rietveld 408576698