Title: [210670] trunk/Source/WebCore
Revision
210670
Author
[email protected]
Date
2017-01-12 10:44:48 -0800 (Thu, 12 Jan 2017)

Log Message

[GTK] WebKitWebProcess at 100% CPU loading hyphenation dictionaries
https://bugs.webkit.org/show_bug.cgi?id=165601

Reviewed by Carlos Garcia Campos.

In HyphenationLibHyphen, retrieve the canonicalized absolute pathname of the dictionary file
in order to avoid storing symbolic links as the target files for specific locales. libhyphen
distributes its dictionary files by linking a set of similar locales files to a single file.
Not resolving those symbolic links means we'll be opening a single file via multiple
HyphenationDictionary objects, which is far from optimal.

To add insult to injury, these HyphenationDictionary objects were stored in a TinyLRUCache
with a slim capacity of 4. This meant that while already loading one single file through
multiple symlinks, because of continuous eviciton from this LRU cache the same symlinks
continued to be processed, in some cases resulting in opening the same dictionary file
hundreds or thousands of times. The capacity of this TinyLRUCache is increased to 32
to keep the amount of open libhyphen dictionaries capped at some reasonable number.

* platform/text/hyphen/HyphenationLibHyphen.cpp:
(WebCore::scanDirectoryForDicionaries):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210669 => 210670)


--- trunk/Source/WebCore/ChangeLog	2017-01-12 18:41:28 UTC (rev 210669)
+++ trunk/Source/WebCore/ChangeLog	2017-01-12 18:44:48 UTC (rev 210670)
@@ -1,3 +1,26 @@
+2017-01-12  Zan Dobersek  <[email protected]>
+
+        [GTK] WebKitWebProcess at 100% CPU loading hyphenation dictionaries
+        https://bugs.webkit.org/show_bug.cgi?id=165601
+
+        Reviewed by Carlos Garcia Campos.
+
+        In HyphenationLibHyphen, retrieve the canonicalized absolute pathname of the dictionary file
+        in order to avoid storing symbolic links as the target files for specific locales. libhyphen
+        distributes its dictionary files by linking a set of similar locales files to a single file.
+        Not resolving those symbolic links means we'll be opening a single file via multiple
+        HyphenationDictionary objects, which is far from optimal.
+
+        To add insult to injury, these HyphenationDictionary objects were stored in a TinyLRUCache
+        with a slim capacity of 4. This meant that while already loading one single file through
+        multiple symlinks, because of continuous eviciton from this LRU cache the same symlinks
+        continued to be processed, in some cases resulting in opening the same dictionary file
+        hundreds or thousands of times. The capacity of this TinyLRUCache is increased to 32
+        to keep the amount of open libhyphen dictionaries capped at some reasonable number.
+
+        * platform/text/hyphen/HyphenationLibHyphen.cpp:
+        (WebCore::scanDirectoryForDicionaries):
+
 2017-01-12  Javier Fernandez  <[email protected]>
 
         [css-grid] Make the grid sizing data persistent through layouts

Modified: trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp (210669 => 210670)


--- trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2017-01-12 18:41:28 UTC (rev 210669)
+++ trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2017-01-12 18:44:48 UTC (rev 210670)
@@ -31,6 +31,8 @@
 
 #include "FileSystem.h"
 #include <hyphen.h>
+#include <limits>
+#include <stdlib.h>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/TinyLRUCache.h>
@@ -62,8 +64,14 @@
 
 static void scanDirectoryForDicionaries(const char* directoryPath, HashMap<AtomicString, Vector<String>>& availableLocales)
 {
-    for (const auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
+    for (auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
         String locale = extractLocaleFromDictionaryFilePath(filePath).convertToASCIILowercase();
+
+        char normalizedPath[PATH_MAX];
+        if (!realpath(fileSystemRepresentation(filePath).data(), normalizedPath))
+            continue;
+
+        filePath = stringFromFileSystemRepresentation(normalizedPath);
         availableLocales.add(locale, Vector<String>()).iterator->value.append(filePath);
 
         String localeReplacingUnderscores = String(locale);
@@ -176,9 +184,9 @@
 class TinyLRUCachePolicy<AtomicString, RefPtr<WebCore::HyphenationDictionary>>
 {
 public:
-    static TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>>& cache()
+    static TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>, 32>& cache()
     {
-        static NeverDestroyed<TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>>> cache;
+        static NeverDestroyed<TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>, 32>> cache;
         return cache;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to