Chromium Code Reviews
Help | Chromium Project | Gerrit Changes | Sign in
(16)

Issue 457413002: Defer late and async scripts (Closed)

Created:
5 years, 4 months ago by Pat Meenan
Modified:
3 years, 7 months ago
Reviewers:
eseidel
CC:
blink-reviews, blink-reviews-html_chromium.org, sof, eae+blinkwatch, blink-reviews-dom_chromium.org, dglazkov+blink, gavinp+loader_chromium.org, Nate Chapin, rwlbuis, igrigorik, oystein (OOO til 10th of July), eseidel, abarth-chromium
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Project:
blink
Visibility:
Public.

Description

Defer late and async scripts Some background: the net loader will treat any Medium or High priority resources discovered before the parser reaches the <body> tag as critical and will block loading of lower priority resources until those have finished loading. This includes resources discovered by the preload scanner (see the bug for implications of this). This patch adds logic to the preload scanner to teach it about the body tag so that resources can be prioritized based on when and how they are referenced, not just when they are discovered. It also changes the prioritization of loading scripts and css: - Scripts with Async or Defer attributes are now loaded with the same priority as images (Very Low) since they do not block parsing or DOM Content Loaded (DCL). Loading them with the same priority as images gives sites some level of control over ordering where async scripts at the top of the document would load earlier and async scripts at the end would load later. Currently async scripts are treated like blocking scripts and are treated as critical resources (blocking all images from loading). - Scripts injected dynamically by creating a script node and attaching it to the document are treated like async scripts (and have the same execution properties). - Scripts written into the page with document.write are processed and given the same priorities as normal parsed scripts (Medium priority). - Scripts and CSS before the body tag are loaded at the same priority (Medium) in the order they were discovered (since they can block each other if they are interleaved). Previously CSS was given a higher priority than scripts. - Scripts and CSS after the body tag are loaded with a Low priority which is higher than non-visible images but low enough that they are not counted as critical resources for the loader. By loading them with a higher priority than images we still get them loaded quickly and avoid blocking the main parser (and delaying page interaction/DCL) while still rendering sooner. - Low-priority scripts that have not loaded by the time the main parser reaches them are re-prioritized as Medium. Practically this should have no impact since they are loaded in order anyway but it it a side-effect of how prioritization is done and has no downside. Desktop test results (some NSFW sites): https://docs.google.com/spreadsheet/ccc?key=0As3TLupYw2RedHNsUUd4dWNDS2RuaHpzVy05UDR0QlE&usp=sharing In testing this improves the metrics across the board: ~3% on Speed Index ~5% on start render ~3% on DOM Content Loaded ~6% on onload Getting out of the critical phase while still loading the scripts before non-visible images are largely why we could improve the visible metrics without degrading the DCL and onload metrics. BUG=317785

Patch Set 1 : Lower priorities for late/async scripts #

Unified diffs Side-by-side diffs Delta from patch set Stats (+137 lines, -7 lines) Patch
M LayoutTests/http/tests/loading/promote-img-in-viewport-priority-expected.txt View 1 chunk +1 line, -1 line 0 comments Download
A LayoutTests/http/tests/loading/resources/body.js View 1 chunk +1 line, -0 lines 0 comments Download
A LayoutTests/http/tests/loading/resources/document-write.js View 1 chunk +1 line, -0 lines 0 comments Download
A LayoutTests/http/tests/loading/resources/head.js View 1 chunk +1 line, -0 lines 0 comments Download
A LayoutTests/http/tests/loading/resources/injected.js View 1 chunk +1 line, -0 lines 0 comments Download
A LayoutTests/http/tests/loading/script-priorities.html View 1 chunk +25 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/loading/script-priorities-expected.txt View 1 chunk +23 lines, -0 lines 0 comments Download
M Source/core/dom/ScriptLoader.h View 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/dom/ScriptLoader.cpp View 4 chunks +9 lines, -0 lines 0 comments Download
M Source/core/fetch/FetchRequest.h View 2 chunks +6 lines, -0 lines 0 comments Download
M Source/core/fetch/FetchRequest.cpp View 3 chunks +6 lines, -0 lines 0 comments Download
M Source/core/fetch/ResourceFetcher.cpp View 1 chunk +13 lines, -2 lines 0 comments Download
M Source/core/fetch/ResourceLoadPriorityOptimizer.cpp View 1 chunk +1 line, -1 line 0 comments Download
M Source/core/html/parser/CSSPreloadScanner.h View 2 chunks +2 lines, -0 lines 0 comments Download
M Source/core/html/parser/CSSPreloadScanner.cpp View 3 chunks +3 lines, -0 lines 0 comments Download
M Source/core/html/parser/HTMLPreloadScanner.h View 2 chunks +4 lines, -1 line 0 comments Download
M Source/core/html/parser/HTMLPreloadScanner.cpp View 10 chunks +28 lines, -2 lines 0 comments Download
M Source/core/html/parser/HTMLResourcePreloader.h View 3 chunks +8 lines, -0 lines 0 comments Download
M Source/core/html/parser/HTMLResourcePreloader.cpp View 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 7 (1 generated)
Pat Meenan
tonyg@ PTAL
5 years, 3 months ago (2014-08-25 15:02:57 UTC) #1
tonyg
Incredible numbers!! :) This all looks reasonable, but I'm a bit scared by the fact ...
5 years, 3 months ago (2014-08-25 22:45:48 UTC) #2
Pat Meenan
On 2014/08/25 22:45:48, tonyg wrote: > Incredible numbers!! :) > > This all looks reasonable, ...
5 years, 3 months ago (2014-08-25 23:30:48 UTC) #3
eseidel
eseidel@chromium.org changed reviewers: + eseidel@chromium.org
5 years, 3 months ago (2014-08-25 23:54:40 UTC) #4
eseidel
Amazing numbers. But the layers upon layers of hacks in our platform boggles the mind. ...
5 years, 3 months ago (2014-08-25 23:54:40 UTC) #5
Pat Meenan
5 years, 3 months ago (2014-08-25 23:58:48 UTC) #6
On 2014/08/25 23:54:40, eseidel wrote:
> Amazing numbers.  But the layers upon layers of hacks in our platform boggles
> the mind. :)

For extra fun the Blink and Net stack priorities are offset by 1 so Medium on
the blink side is Low on the net side.  Makes it really interesting to keep
straight working on both sides.  I considered trying to clean that up but both
have external customers other than Chrome :-(

Powered by Google App Engine
This is Rietveld 408576698