From 698c78ce3ccc545c2d5bbbe456403016f1b3fcab Mon Sep 17 00:00:00 2001 From: "zandobersek@gmail.com" Date: Thu, 12 Jan 2017 18:44:48 +0000 Subject: [PATCH] [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): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210670 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 23 ++++++++++++++++++++++ .../platform/text/hyphen/HyphenationLibHyphen.cpp | 14 ++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index c54e983..213546a 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,26 @@ +2017-01-12 Zan Dobersek + + [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 [css-grid] Make the grid sizing data persistent through layouts diff --git a/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp b/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp index f497e5b..f7b8011 100644 --- a/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp +++ b/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp @@ -31,6 +31,8 @@ #include "FileSystem.h" #include +#include +#include #include #include #include @@ -62,8 +64,14 @@ static String extractLocaleFromDictionaryFilePath(const String& filePath) static void scanDirectoryForDicionaries(const char* directoryPath, HashMap>& 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()).iterator->value.append(filePath); String localeReplacingUnderscores = String(locale); @@ -176,9 +184,9 @@ template<> class TinyLRUCachePolicy> { public: - static TinyLRUCache>& cache() + static TinyLRUCache, 32>& cache() { - static NeverDestroyed>> cache; + static NeverDestroyed, 32>> cache; return cache; } -- 1.8.3.1