Title: [237040] trunk/Source/WebCore
Revision
237040
Author
[email protected]
Date
2018-10-11 11:39:05 -0700 (Thu, 11 Oct 2018)

Log Message

Use finer grained locking in FontDatabase
https://bugs.webkit.org/show_bug.cgi?id=190467

Reviewed by Alex Christensen.

* platform/graphics/FontCache.h:

Also use ListHashSet for prewarming info so we can prewarm in the same order the fonts were
seen last time.

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontDatabase::collectionForFamily):

Only hold the lock when accessing the hashmap. There is no need to hold it during font construction
which can take a long time.

(WebCore::FontDatabase::fontForPostScriptName):

This is currently not prewarmed from a thread so no need for locking.

(WebCore::FontDatabase::clear):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (237039 => 237040)


--- trunk/Source/WebCore/ChangeLog	2018-10-11 18:35:49 UTC (rev 237039)
+++ trunk/Source/WebCore/ChangeLog	2018-10-11 18:39:05 UTC (rev 237040)
@@ -1,3 +1,27 @@
+2018-10-11  Antti Koivisto  <[email protected]>
+
+        Use finer grained locking in FontDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=190467
+
+        Reviewed by Alex Christensen.
+
+        * platform/graphics/FontCache.h:
+
+        Also use ListHashSet for prewarming info so we can prewarm in the same order the fonts were
+        seen last time.
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontDatabase::collectionForFamily):
+
+        Only hold the lock when accessing the hashmap. There is no need to hold it during font construction
+        which can take a long time.
+
+        (WebCore::FontDatabase::fontForPostScriptName):
+
+        This is currently not prewarmed from a thread so no need for locking.
+
+        (WebCore::FontDatabase::clear):
+
 2018-10-11  Thibault Saunier  <[email protected]>
 
         [GStreamer] Fix race condition in GStreamerVideoDecoder

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (237039 => 237040)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2018-10-11 18:35:49 UTC (rev 237039)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2018-10-11 18:39:05 UTC (rev 237040)
@@ -36,6 +36,7 @@
 #include <array>
 #include <limits.h>
 #include <wtf/Forward.h>
+#include <wtf/ListHashSet.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 #include <wtf/WorkQueue.h>
@@ -264,7 +265,7 @@
     bool m_shouldMockBoldSystemFontForAccessibility { false };
 
 #if PLATFORM(COCOA)
-    HashSet<String> m_seenFamiliesForPrewarming;
+    ListHashSet<String> m_seenFamiliesForPrewarming;
     RefPtr<WorkQueue> m_prewarmQueue;
 
     friend class ComplexTextController;

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (237039 => 237040)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-10-11 18:35:49 UTC (rev 237039)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-10-11 18:39:05 UTC (rev 237040)
@@ -887,10 +887,15 @@
 
     const InstalledFontFamily& collectionForFamily(const String& familyName)
     {
-        std::lock_guard<Lock> locker(m_descriptorMapLock);
+        auto folded = familyName.foldCase();
+        {
+            std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+            auto it = m_familyNameToFontDescriptors.find(folded);
+            if (it != m_familyNameToFontDescriptors.end())
+                return it->value;
+        }
 
-        auto folded = familyName.foldCase();
-        return m_familyNameToFontDescriptors.ensure(folded, [&] {
+        auto installedFontFamily = [&] {
             auto familyNameString = folded.createCFString();
             auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             CFDictionaryAddValue(attributes.get(), kCTFontFamilyNameAttribute, familyNameString.get());
@@ -908,13 +913,14 @@
                 return InstalledFontFamily(WTFMove(result));
             }
             return InstalledFontFamily();
-        }).iterator->value;
+        }();
+
+        std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+        return m_familyNameToFontDescriptors.add(folded.isolatedCopy(), installedFontFamily).iterator->value;
     }
 
     const InstalledFont& fontForPostScriptName(const AtomicString& postScriptName)
     {
-        std::lock_guard<Lock> locker(m_descriptorMapLock);
-
         const auto& folded = FontCascadeDescription::foldedFamilyName(postScriptName);
         return m_postScriptNameToFontDescriptors.ensure(folded, [&] {
             auto postScriptNameString = folded.createCFString();
@@ -936,9 +942,10 @@
 
     void clear()
     {
-        std::lock_guard<Lock> locker(m_descriptorMapLock);
-
-        m_familyNameToFontDescriptors.clear();
+        {
+            std::lock_guard<Lock> locker(m_familyNameToFontDescriptorsLock);
+            m_familyNameToFontDescriptors.clear();
+        }
         m_postScriptNameToFontDescriptors.clear();
     }
 
@@ -950,7 +957,7 @@
     {
     }
 
-    Lock m_descriptorMapLock;
+    Lock m_familyNameToFontDescriptorsLock;
     HashMap<String, InstalledFontFamily> m_familyNameToFontDescriptors;
     HashMap<String, InstalledFont> m_postScriptNameToFontDescriptors;
     AllowUserInstalledFonts m_allowUserInstalledFonts;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to