Title: [274985] trunk/Source/WebCore
Revision
274985
Author
[email protected]
Date
2021-03-24 17:05:48 -0700 (Wed, 24 Mar 2021)

Log Message

Move TelephoneNumberDetector preloading off the main thread
https://bugs.webkit.org/show_bug.cgi?id=223715

Reviewed by Geoffrey Garen.

Move TelephoneNumberDetector preloading off the main thread. We have evidence that prewarmGlobally() can be slow and hang the main
thread for too long (rdar://75279383). As a result, it is a good idea to prewarm things off the main thread whenever possible.

* page/ProcessWarming.cpp:
(WebCore::ProcessWarming::prewarmGlobally):
* platform/TelephoneNumberDetector.h:
* platform/cocoa/TelephoneNumberDetectorCocoa.cpp:
(WebCore::TelephoneNumberDetector::phoneNumbersScanner):
(WebCore::TelephoneNumberDetector::prewarm):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274984 => 274985)


--- trunk/Source/WebCore/ChangeLog	2021-03-25 00:04:42 UTC (rev 274984)
+++ trunk/Source/WebCore/ChangeLog	2021-03-25 00:05:48 UTC (rev 274985)
@@ -1,3 +1,20 @@
+2021-03-24  Chris Dumez  <[email protected]>
+
+        Move TelephoneNumberDetector preloading off the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=223715
+
+        Reviewed by Geoffrey Garen.
+
+        Move TelephoneNumberDetector preloading off the main thread. We have evidence that prewarmGlobally() can be slow and hang the main
+        thread for too long (rdar://75279383). As a result, it is a good idea to prewarm things off the main thread whenever possible.
+
+        * page/ProcessWarming.cpp:
+        (WebCore::ProcessWarming::prewarmGlobally):
+        * platform/TelephoneNumberDetector.h:
+        * platform/cocoa/TelephoneNumberDetectorCocoa.cpp:
+        (WebCore::TelephoneNumberDetector::phoneNumbersScanner):
+        (WebCore::TelephoneNumberDetector::prewarm):
+
 2021-03-24  Eric Carlson  <[email protected]>
 
         [Cocoa] Add Experimental MediaSession coordinator

Modified: trunk/Source/WebCore/page/ProcessWarming.cpp (274984 => 274985)


--- trunk/Source/WebCore/page/ProcessWarming.cpp	2021-03-25 00:04:42 UTC (rev 274984)
+++ trunk/Source/WebCore/page/ProcessWarming.cpp	2021-03-25 00:05:48 UTC (rev 274985)
@@ -81,7 +81,7 @@
     FontCache::singleton().prewarmGlobally();
 
 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
-    TelephoneNumberDetector::isSupported();
+    TelephoneNumberDetector::prewarm();
 #endif
 
 #if ENABLE(GPU_DRIVER_PREWARMING)

Modified: trunk/Source/WebCore/platform/TelephoneNumberDetector.h (274984 => 274985)


--- trunk/Source/WebCore/platform/TelephoneNumberDetector.h	2021-03-25 00:04:42 UTC (rev 274984)
+++ trunk/Source/WebCore/platform/TelephoneNumberDetector.h	2021-03-25 00:05:48 UTC (rev 274985)
@@ -33,6 +33,7 @@
 namespace WebCore {
 namespace TelephoneNumberDetector {
 
+void prewarm();
 bool isSupported();
 bool find(const UChar* buffer, unsigned length, int* startPos, int* endPos);
 

Modified: trunk/Source/WebCore/platform/cocoa/TelephoneNumberDetectorCocoa.cpp (274984 => 274985)


--- trunk/Source/WebCore/platform/cocoa/TelephoneNumberDetectorCocoa.cpp	2021-03-25 00:04:42 UTC (rev 274984)
+++ trunk/Source/WebCore/platform/cocoa/TelephoneNumberDetectorCocoa.cpp	2021-03-25 00:05:48 UTC (rev 274985)
@@ -47,15 +47,23 @@
 
 static DDDFAScannerRef phoneNumbersScanner()
 {
-    if (!DataDetectorsCoreLibrary())
-        return nullptr;
+    static NeverDestroyed<RetainPtr<DDDFAScannerRef>> scanner;
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        if (DataDetectorsCoreLibrary()) {
+            if (auto cache = adoptCF(DDDFACacheCreateFromFramework()))
+                scanner.get() = adoptCF(DDDFAScannerCreateFromCache(cache.get()));
+        }
+    });
+    return scanner.get().get();
+}
 
-    static struct __DDDFACache* cache = DDDFACacheCreateFromFramework();
-    if (!cache)
-        return nullptr;
-
-    static DDDFAScannerRef scanner = DDDFAScannerCreateFromCache(cache);
-    return scanner;
+void prewarm()
+{
+    // Prewarm on a background queue to avoid hanging the main thread.
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        phoneNumbersScanner();
+    });
 }
 
 bool isSupported()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to