Slightly delay rendering for <link rel=preload> fonts
Design doc: https://bit.ly/36E8UKB
This patch introduces the following logic, so that preloaded fonts
have a higher chance to meet the first rendering lifecycle:
- When <link rel=preload> starts to load a font, register it to
FontPreloadManager
- FontPreloadManager blocks lifecycle updates if any font is being
preloaded
- FontPreloadManager resumes lifecycle updates if font preloading
finishes, or a short timeout is fired
Handling of Font Loading API and 'font-display: optional' will be
done by followup patches.
Bug: 1040632
Change-Id: Ib58416830156ee8b296b7d9d39e3fea3a50960b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006626
Reviewed-by: Chris Harrelson <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#746936}
diff --git a/third_party/blink/common/features.cc b/third_party/blink/common/features.cc
index c615a9d..3f09ab8b8 100644
--- a/third_party/blink/common/features.cc
+++ b/third_party/blink/common/features.cc
@@ -481,5 +481,17 @@
const base::Feature kBlockHTMLParserOnStyleSheets{
"BlockHTMLParserOnStyleSheets", base::FEATURE_DISABLED_BY_DEFAULT};
+// Slightly delays rendering if there are fonts being preloaded, so that
+// they don't miss the first paint if they can be loaded fast enough (e.g.,
+// from the disk cache)
+const base::Feature kFontPreloadingDelaysRendering{
+ "FontPreloadingDelaysRendering", base::FEATURE_DISABLED_BY_DEFAULT};
+
+// Set to be over 90th-percentile of HttpCache.AccessToDone.Used on all
+// platforms, and also to allow some time for IPC and scheduling.
+// TODO(xiaochengh): Tune it for the best performance.
+const base::FeatureParam<int> kFontPreloadingDelaysRenderingParam{
+ &kFontPreloadingDelaysRendering, "delay-in-ms", 100};
+
} // namespace features
} // namespace blink