Prewarm font cache with more fonts
https://bugs.webkit.org/show_bug.cgi?id=199283
Reviewed by Myles C. Maxfield.
Use the existing prewarm method in FontCache to prewarm the cache with a set of font family names.
The font list consists of some of the fonts used by the 10 most popular sites on Alexa top sites.
This is a confirmed improvement in page load time.
No new tests, covered by existing tests.
* page/ProcessWarming.cpp:
(WebCore::ProcessWarming::prewarmGlobally):
* platform/graphics/FontCache.cpp:
(WebCore::FontCache::prewarmGlobally):
* platform/graphics/FontCache.h:
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontCache::prewarmGlobally):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@247498 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index bca5655..03a8fa7 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2019-07-16 Per Arne Vollan <pvollan@apple.com>
+
+ Prewarm font cache with more fonts
+ https://bugs.webkit.org/show_bug.cgi?id=199283
+
+ Reviewed by Myles C. Maxfield.
+
+ Use the existing prewarm method in FontCache to prewarm the cache with a set of font family names.
+ The font list consists of some of the fonts used by the 10 most popular sites on Alexa top sites.
+ This is a confirmed improvement in page load time.
+
+ No new tests, covered by existing tests.
+
+ * page/ProcessWarming.cpp:
+ (WebCore::ProcessWarming::prewarmGlobally):
+ * platform/graphics/FontCache.cpp:
+ (WebCore::FontCache::prewarmGlobally):
+ * platform/graphics/FontCache.h:
+ * platform/graphics/cocoa/FontCacheCoreText.cpp:
+ (WebCore::FontCache::prewarmGlobally):
+
2019-07-16 Robin Morisset <rmorisset@apple.com>
[WHLSL] Desugar for loops and while loops
diff --git a/Source/WebCore/page/ProcessWarming.cpp b/Source/WebCore/page/ProcessWarming.cpp
index 26aeac2..a071c50 100644
--- a/Source/WebCore/page/ProcessWarming.cpp
+++ b/Source/WebCore/page/ProcessWarming.cpp
@@ -58,7 +58,7 @@
XMLNames::init();
WebKitFontFamilyNames::init();
}
-
+
void ProcessWarming::prewarmGlobally()
{
initializeNames();
@@ -72,14 +72,8 @@
// Prewarms JS VM.
commonVM();
-#if USE(PLATFORM_SYSTEM_FALLBACK_LIST)
- // Cache system UI font fallbacks. Almost every web process needs these.
- // Initializing one size is sufficient to warm CoreText caches.
- FontCascadeDescription systemFontDescription;
- systemFontDescription.setOneFamily("system-ui");
- systemFontDescription.setComputedSize(11);
- systemFontDescription.effectiveFamilyCount();
-#endif
+ // Prewarm font cache
+ FontCache::singleton().prewarmGlobally();
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
TelephoneNumberDetector::isSupported();
diff --git a/Source/WebCore/platform/graphics/FontCache.cpp b/Source/WebCore/platform/graphics/FontCache.cpp
index d2d0b79..0a62a27 100644
--- a/Source/WebCore/platform/graphics/FontCache.cpp
+++ b/Source/WebCore/platform/graphics/FontCache.cpp
@@ -488,6 +488,10 @@
return { };
}
+void FontCache::prewarmGlobally()
+{
+}
+
void FontCache::prewarm(const PrewarmInformation&)
{
}
diff --git a/Source/WebCore/platform/graphics/FontCache.h b/Source/WebCore/platform/graphics/FontCache.h
index 5cae8ac..844ba44 100644
--- a/Source/WebCore/platform/graphics/FontCache.h
+++ b/Source/WebCore/platform/graphics/FontCache.h
@@ -252,6 +252,7 @@
};
PrewarmInformation collectPrewarmInformation() const;
void prewarm(const PrewarmInformation&);
+ void prewarmGlobally();
private:
FontCache();
diff --git a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
index 062929c..6a0e098 100644
--- a/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
+++ b/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
@@ -36,6 +36,7 @@
#include <wtf/HashSet.h>
#include <wtf/MainThread.h>
+#include <wtf/MemoryPressureHandler.h>
#include <wtf/NeverDestroyed.h>
#define HAS_CORE_TEXT_WIDTH_ATTRIBUTE ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000))
@@ -1621,4 +1622,23 @@
});
}
+void FontCache::prewarmGlobally()
+{
+ if (MemoryPressureHandler::singleton().isUnderMemoryPressure())
+ return;
+
+ Vector<String> families = std::initializer_list<String> {
+ "Arial"_s,
+ "Helvetica"_s,
+ "Helvetica Neue"_s,
+ "SF Pro Text"_s,
+ "Times"_s,
+ "Times New Roman"_s,
+ };
+
+ FontCache::PrewarmInformation prewarmInfo;
+ prewarmInfo.seenFamilies = WTFMove(families);
+ FontCache::singleton().prewarm(prewarmInfo);
+}
+
}