Title: [237357] trunk/Source/WebCore
Revision
237357
Author
[email protected]
Date
2018-10-23 11:02:32 -0700 (Tue, 23 Oct 2018)

Log Message

topPrivatelyControlledDomain is slow
https://bugs.webkit.org/show_bug.cgi?id=190792

Reviewed by Alex Christensen.

It calls into some slowish CFNetwork code and ends up showing up in profiles.

* platform/mac/PublicSuffixMac.mm:
(WebCore::topPrivatelyControlledDomain):

Add a cache that avoids calls into frameworks.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (237356 => 237357)


--- trunk/Source/WebCore/ChangeLog	2018-10-23 17:54:57 UTC (rev 237356)
+++ trunk/Source/WebCore/ChangeLog	2018-10-23 18:02:32 UTC (rev 237357)
@@ -1,3 +1,17 @@
+2018-10-23  Antti Koivisto  <[email protected]>
+
+        topPrivatelyControlledDomain is slow
+        https://bugs.webkit.org/show_bug.cgi?id=190792
+
+        Reviewed by Alex Christensen.
+
+        It calls into some slowish CFNetwork code and ends up showing up in profiles.
+
+        * platform/mac/PublicSuffixMac.mm:
+        (WebCore::topPrivatelyControlledDomain):
+
+        Add a cache that avoids calls into frameworks.
+
 2018-10-23  Chris Dumez  <[email protected]>
 
         [PSON] Add support for cross-site client-side redirects

Modified: trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm (237356 => 237357)


--- trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm	2018-10-23 17:54:57 UTC (rev 237356)
+++ trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm	2018-10-23 18:02:32 UTC (rev 237357)
@@ -31,6 +31,8 @@
 #import "URL.h"
 #import "WebCoreNSURLExtras.h"
 #import <pal/spi/cf/CFNetworkSPI.h>
+#import <wtf/HashMap.h>
+#import <wtf/text/StringHash.h>
 
 namespace WebCore {
 
@@ -43,22 +45,35 @@
 
 String topPrivatelyControlledDomain(const String& domain)
 {
-    if (URL::hostIsIPAddress(domain))
+    if (domain.isEmpty() || !domain.isAllASCII())
         return domain;
 
-    if (!domain.isAllASCII())
-        return domain;
-    
-    const auto& lowercaseDomain = domain.convertToASCIILowercase();
-    if (lowercaseDomain == "localhost")
-        return lowercaseDomain;
+    static NeverDestroyed<HashMap<String, String, ASCIICaseInsensitiveHash>> cache;
+    static Lock cacheLock;
 
-    size_t separatorPosition;
-    for (unsigned labelStart = 0; (separatorPosition = lowercaseDomain.find('.', labelStart)) != notFound; labelStart = separatorPosition + 1) {
-        if (isPublicSuffix(lowercaseDomain.substring(separatorPosition + 1)))
-            return lowercaseDomain.substring(labelStart);
-    }
-    return String();
+    auto isolatedDomain = domain.isolatedCopy();
+
+    auto locker = holdLock(cacheLock);
+
+    constexpr auto maximumSizeToPreventUnlimitedGrowth = 128;
+    if (cache.get().size() == maximumSizeToPreventUnlimitedGrowth)
+        cache.get().clear();
+
+    return cache.get().ensure(isolatedDomain, [&isolatedDomain] {
+        const auto lowercaseDomain = isolatedDomain.convertToASCIILowercase();
+        if (lowercaseDomain == "localhost")
+            return lowercaseDomain;
+
+        if (URL::hostIsIPAddress(lowercaseDomain))
+            return lowercaseDomain;
+
+        size_t separatorPosition;
+        for (unsigned labelStart = 0; (separatorPosition = lowercaseDomain.find('.', labelStart)) != notFound; labelStart = separatorPosition + 1) {
+            if (isPublicSuffix(lowercaseDomain.substring(separatorPosition + 1)))
+                return lowercaseDomain.substring(labelStart);
+        }
+        return String();
+    }).iterator->value.isolatedCopy();
 }
 
 String decodeHostName(const String& domain)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to