New issue
Advanced search Search tips

Issue 596676 link

Starred by 4 users

Issue metadata

Status: WontFix
Owner:
Closed: Aug 22
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug

Blocking:
issue 641880



Sign in to add a comment

Preload @imports in incoming CSS before they are parsed

Project Member Reported by csharrison@chromium.org, Mar 21 2016

Issue description

We currently wait for the script to be parsed before initiating the fetch. This could take awhile if e.g. there are parser blocking elements (i.e. resource fetches or synchronous scripts).

Most CSS should be preloaded in this case. I.e. their fetches will sometimes complete before they are ready to be parsed. In these cases, we should scan the preloaded CSS for @imports just as we scan inline css.
 
Cc: kinuko@chromium.org toyoshim@chromium.org
This seems related to  issue 558105 .
We were wondering if this is worth the effort / added complexity.

What are your thoughts about how much efforts and complexity this represents?

Regardless, we should have metrics on this. I'm thinking that we should know:
 - how big the opportunity is
 - how much time we've saved
I ran a brief analysis in WPT over 280 urls to track frequency. Results show that this will affect 3-4% of pages. I don't have improvement metrics yet, but a draft CL that implements this feature was rather simple. We just add a new ResourceClient that feeds into a CSSPreloadScanner.

The majority of the complexity is handled by the existing stack. I can run a localized test over those URLs that are affected by this change to get improvement metrics.
Thanks!

Given the low complexity, 3-4% is great.
+1 for a lab test to get a rough sense of what to expect.
I did a provisional lab test. Here's a doc highlighting some findings:
https://docs.google.com/a/google.com/document/d/1BNNe8MFC1jkRCtnAddHxaaZZWM_loC_WQyG_wu2Y4zg/pub

I don't have enough URLs at the moment to do a bigger test. I'll see if I can throw up my CL for review to see if it is architecturally sound.
From a quick read, this looks promising :)
One question, are we always able to resolve media queries at the time we want to preload @imports? If we can't then I believe that this is the only possible reason why we might be wasting bytes.
Project Member

Comment 8 by bugdroid1@chromium.org, Apr 29 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/c3698d693def17f7f4c2d17f462de63ee06fe10d

commit c3698d693def17f7f4c2d17f462de63ee06fe10d
Author: csharrison <csharrison@chromium.org>
Date: Fri Apr 29 17:07:15 2016

Preload scan external css for @import

This change adds a StyleSheetResourceClient on all CSS
preloads. The client holds a CSSPreloadScanner which receives
the stream of CSS as it comes in.

BUG= 596676 

Review-Url: https://codereview.chromium.org/1819593002
Cr-Commit-Position: refs/heads/master@{#390678}

[add] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_preload.html
[add] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/LayoutTests/http/tests/resources/css_with_import.css
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/fetch/StyleSheetResourceClient.h
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.h
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.h
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/HTMLResourcePreloader.cpp
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/core/html/parser/HTMLResourcePreloader.h
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in
[modify] https://crrev.com/c3698d693def17f7f4c2d17f462de63ee06fe10d/tools/metrics/histograms/histograms.xml

Charles, this came up again on my radar in the context of using @import as a ping (for usage accountability by webfont services*.

What's the status?
 - Did you have the time to run a lab experiment to gauge the potential?
 - Should we plan an experiment?


*: I'm discussing a better alternative for this use case, in the form of an HTTP link rel ping. That being said it's probably a really small fraction of the @import usage so this optimization is still interesting.

I have a draft CL that I haven't had cycles to polish up and ship. I have a number of experiments going out right now and I thought this one would have the least impact.

That being said, most of the code is written. It just needs some tests. I may have some time in Q3 to finally land it :)

I would be more excited about the patch if there were future plans to do more scanning of CSS resources like webfonts. @import in external css is rather rare.
Project Member

Comment 11 by bugdroid1@chromium.org, Aug 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/c016ef022ac17d029d61bc79d8a8996c053556f3

commit c016ef022ac17d029d61bc79d8a8996c053556f3
Author: csharrison <csharrison@chromium.org>
Date: Fri Aug 26 18:30:08 2016

Preload scan external CSS for @import

This change adds a StyleSheetResourceClient on all CSS
preloads. The client holds a CSSPreloadScanner which receives
the stream of CSS as it comes in.

This is guarded by two Blink settings,
cssExternalScannerPreload and cssExternalScannerNoPreload.
The former allows for scanning and preloading and the latter just
allows for scanning, as a baseline for the overhead of the feature.

This is partially a reland of
https://codereview.chromium.org/1819593002, which was
reverted manually here:
https://codereview.chromium.org/1947053002/

The revert was due to a crash and some faulty logic with
regard to all css preload requests being considered
"referenced". This CL attempts to fix that by adding an enum
to mark a ResourceClient as "passive".

BUG= 610437 , 596676 

Review-Url: https://codereview.chromium.org/1976463003
Cr-Commit-Position: refs/heads/master@{#414756}

[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/chrome/browser/chrome_content_browser_client.cc
[add] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_no_scanning.html
[add] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_preload.html
[add] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_scan_only.html
[add] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/LayoutTests/http/tests/resources/css_with_import.css
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/core.gypi
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/ImageResource.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/Resource.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/Resource.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/ResourceOwner.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/fetch/StyleSheetResourceClient.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/frame/Settings.in
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.h
[add] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/HTMLResourcePreloader.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/html/parser/HTMLResourcePreloader.h
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/Source/core/loader/DocumentLoader.cpp
[modify] https://crrev.com/c016ef022ac17d029d61bc79d8a8996c053556f3/third_party/WebKit/public/platform/WebLoadingBehaviorFlag.h

Project Member

Comment 12 by bugdroid1@chromium.org, Aug 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/dee540ca7dff49cf44ed84443e2d266e462e2c52

commit dee540ca7dff49cf44ed84443e2d266e462e2c52
Author: csharrison <csharrison@chromium.org>
Date: Fri Aug 26 19:51:37 2016

Add histogram to track overhead for scanning external css

This patch adds a histogram to count the microseconds used to preload
scan the first chunk of CSS for the @import scanning experiment.

BUG= 596676 

Review-Url: https://codereview.chromium.org/2283803002
Cr-Commit-Position: refs/heads/master@{#414787}

[modify] https://crrev.com/dee540ca7dff49cf44ed84443e2d266e462e2c52/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp
[modify] https://crrev.com/dee540ca7dff49cf44ed84443e2d266e462e2c52/tools/metrics/histograms/histograms.xml

Blocking: 641880
Project Member

Comment 15 by bugdroid1@chromium.org, Oct 27 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/90f9f786e88b196d391e6daffb4c9ab7ca7087ab

commit 90f9f786e88b196d391e6daffb4c9ab7ca7087ab
Author: csharrison <csharrison@chromium.org>
Date: Thu Oct 27 21:30:20 2016

Add field trial config for CSSExternalScanner experiment

BUG= 596676 

Review-Url: https://codereview.chromium.org/2454823004
Cr-Commit-Position: refs/heads/master@{#428146}

[modify] https://crrev.com/90f9f786e88b196d391e6daffb4c9ab7ca7087ab/testing/variations/fieldtrial_testing_config.json

Project Member

Comment 16 by bugdroid1@chromium.org, Oct 31 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9ca202f973a177b0a02343cfbab213b85a67728b

commit 9ca202f973a177b0a02343cfbab213b85a67728b
Author: csharrison <csharrison@chromium.org>
Date: Mon Oct 31 20:23:32 2016

Add ParseStartToFirstContentfulPaint metric to @import css scanner

We currently only have parse start to first meaningful paint. Since the
metric is still experimental let's make sure the experiment has at least
one stable metric.

BUG= 596676 

Review-Url: https://codereview.chromium.org/2462083002
Cr-Commit-Position: refs/heads/master@{#428784}

[modify] https://crrev.com/9ca202f973a177b0a02343cfbab213b85a67728b/chrome/browser/page_load_metrics/observers/css_scanning_page_load_metrics_observer.cc
[modify] https://crrev.com/9ca202f973a177b0a02343cfbab213b85a67728b/chrome/browser/page_load_metrics/observers/css_scanning_page_load_metrics_observer.h
[modify] https://crrev.com/9ca202f973a177b0a02343cfbab213b85a67728b/tools/metrics/histograms/histograms.xml

Project Member

Comment 17 by bugdroid1@chromium.org, Nov 17 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/3224ae9404f9395a7f293b57da6cebe2f2371be5

commit 3224ae9404f9395a7f293b57da6cebe2f2371be5
Author: csharrison <csharrison@chromium.org>
Date: Thu Nov 17 14:24:19 2016

Make CSSPreloaderResourceClient hold weak references to its resource

We don't want the client to hold on to the resources for longer than
necessary. This patch enforces this invariant by making the object
to longer a ResourceOwner, and instead hold a WeakMember to the style
resource.

BUG= 596676 

Review-Url: https://codereview.chromium.org/2452413002
Cr-Commit-Position: refs/heads/master@{#432864}

[modify] https://crrev.com/3224ae9404f9395a7f293b57da6cebe2f2371be5/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp
[modify] https://crrev.com/3224ae9404f9395a7f293b57da6cebe2f2371be5/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.h

Project Member

Comment 18 by bugdroid1@chromium.org, Dec 1 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8b58b651ee02a1ec7edde005e6d8a27cca9bae31

commit 8b58b651ee02a1ec7edde005e6d8a27cca9bae31
Author: csharrison <csharrison@chromium.org>
Date: Thu Dec 01 17:46:13 2016

Ensure CSS scanner does not mark preloads as referenced

A recent metrics fix (r432864) also mistakenly broke this code by not
passing in a default argument. This CL fixes that problem and adds an
expectation in unit tests.

BUG= 662999 , 596676 

Review-Url: https://codereview.chromium.org/2544583003
Cr-Commit-Position: refs/heads/master@{#435643}

[modify] https://crrev.com/8b58b651ee02a1ec7edde005e6d8a27cca9bae31/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp
[modify] https://crrev.com/8b58b651ee02a1ec7edde005e6d8a27cca9bae31/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp

Project Member

Comment 19 by bugdroid1@chromium.org, Aug 22

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02

commit 10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02
Author: Charlie Harrison <csharrison@chromium.org>
Date: Wed Aug 22 16:55:41 2018

Remove the CSSExternalScanner code

This feature never launched to stable, and beta results were lukewarm.

Bug: 871496, 596676 
Change-Id: I9628acd33c50bff7ddf3cf612c6bbe963a3c4682
Reviewed-on: https://chromium-review.googlesource.com/1183634
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585096}
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/chrome/browser/chrome_content_browser_client.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/chrome/browser/chrome_content_browser_client_unittest.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/testing/variations/fieldtrial_testing_config.json
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/css-import-loop-crash.html
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/css-import-scan-recursive-expected.txt
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/css-import-scan-recursive.html
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_no_scanning.html
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_preload.html
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/external_css_import_scan_only.html
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/resources/import-loop1.css
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/WebKit/LayoutTests/http/tests/preload/resources/import-loop2.css
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/BUILD.gn
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/frame/settings.json5
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/css_preload_scanner.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/css_preload_scanner.h
[delete] https://crrev.com/fc5a4ccc9a0c2008dc7f6fa1788e22c2d64d5e2d/third_party/blink/renderer/core/html/parser/css_preload_scanner_test.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/html_preload_scanner_test.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/html_resource_preloader.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/html_resource_preloader.h
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/preload_request.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/html/parser/preload_request.h
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/loader/document_loader.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/loader/document_loader.h
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/third_party/blink/renderer/core/loader/link_loader.cc
[modify] https://crrev.com/10d3b3c20ff9df2c7e10ea6b537f9e44d02fff02/tools/metrics/histograms/histograms.xml

Status: WontFix (was: Started)
Beta wins weren't all that great, and the feature was non-trivial to maintain.

Sign in to add a comment