Title: [255988] trunk
Revision
255988
Author
mmaxfi...@apple.com
Date
2020-02-06 15:31:17 -0800 (Thu, 06 Feb 2020)

Log Message

REGRESSION(r254534): 1-3% regression on PLT
https://bugs.webkit.org/show_bug.cgi?id=207244
<rdar://problem/58821709>

Reviewed by Simon Fraser.

Source/WebCore:

Turns out CTFontTransformGlyphsWithLanguage() is 33.7% slower than CTFontTransformGlyphs() on some OSes.
This patch changes the preprocessor guards to not use the function on those OSes.
Also, the contract of the function on the more performant OSes requires that the locale name be canonicalized,
so this patch implements a canonical locale cache inside LocaleMac.mm. It gets cleared when the low memory
warning is fired.

Marked existing tests as failing.

* page/cocoa/MemoryReleaseCocoa.mm:
(WebCore::platformReleaseMemory):
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::applyTransforms const):
* platform/graphics/mac/SimpleFontDataCoreText.cpp:
(WebCore::Font::getCFStringAttributes const):
* platform/text/mac/LocaleMac.h:
* platform/text/mac/LocaleMac.mm:
(WebCore::determineLocale):
(WebCore::canonicalLocaleMap):
(WebCore::LocaleMac::canonicalLanguageIdentifierFromString):
(WebCore::LocaleMac::releaseMemory):

Source/WTF:

CTFontTransformGlyphsWithLanguage() is only acceptable on certain OSes.

* wtf/PlatformHave.h:

LayoutTests:

Mark the tests as failing on certain OSes.

* platform/ios/TestExpectations:
* platform/mac/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (255987 => 255988)


--- trunk/LayoutTests/ChangeLog	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/LayoutTests/ChangeLog	2020-02-06 23:31:17 UTC (rev 255988)
@@ -1,3 +1,16 @@
+2020-02-06  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        REGRESSION(r254534): 1-3% regression on PLT
+        https://bugs.webkit.org/show_bug.cgi?id=207244
+        <rdar://problem/58821709>
+
+        Reviewed by Simon Fraser.
+
+        Mark the tests as failing on certain OSes.
+
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+
 2020-02-06  Devin Rousso  <drou...@apple.com>
 
         Web Inspector: show _javascript_ Worker terminated state as an internal property

Modified: trunk/LayoutTests/platform/ios/TestExpectations (255987 => 255988)


--- trunk/LayoutTests/platform/ios/TestExpectations	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2020-02-06 23:31:17 UTC (rev 255988)
@@ -3480,4 +3480,8 @@
 
 webkit.org/b/207230 imported/w3c/web-platform-tests/fetch/stale-while-revalidate/fetch.html [ Pass Failure ]
 
-webkit.org/b/207278 imported/w3c/web-platform-tests/web-animations/timing-model/animations/finishing-an-animation.html [ Pass Failure ]
\ No newline at end of file
+webkit.org/b/207278 imported/w3c/web-platform-tests/web-animations/timing-model/animations/finishing-an-animation.html [ Pass Failure ]
+
+# Locale-specific shaping is only enabled on certain OSes.
+webkit.org/b/77568 fast/text/locale-shaping.html [ ImageOnlyFailure ]
+webkit.org/b/77568 fast/text/locale-shaping-complex.html [ ImageOnlyFailure ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (255987 => 255988)


--- trunk/LayoutTests/platform/mac/TestExpectations	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2020-02-06 23:31:17 UTC (rev 255988)
@@ -1931,8 +1931,8 @@
 webkit.org/b/204312 imported/w3c/web-platform-tests/svg/import/struct-dom-06-b-manual.svg [ Failure Pass ]
 
 # Locale-specific shaping is only enabled on certain OSes.
-webkit.org/b/77568 [ Sierra HighSierra Mojave ] fast/text/locale-shaping.html [ ImageOnlyFailure ]
-webkit.org/b/77568 [ Sierra HighSierra Mojave ] fast/text/locale-shaping-complex.html [ ImageOnlyFailure ]
+webkit.org/b/77568 [ Sierra HighSierra Mojave Catalina ] fast/text/locale-shaping.html [ ImageOnlyFailure ]
+webkit.org/b/77568 [ Sierra HighSierra Mojave Catalina ] fast/text/locale-shaping-complex.html [ ImageOnlyFailure ]
 
 webkit.org/b/203222 svg/wicd/rightsizing-grid.xhtml [ Pass Failure ]
 

Modified: trunk/Source/WTF/ChangeLog (255987 => 255988)


--- trunk/Source/WTF/ChangeLog	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WTF/ChangeLog	2020-02-06 23:31:17 UTC (rev 255988)
@@ -1,3 +1,15 @@
+2020-02-06  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        REGRESSION(r254534): 1-3% regression on PLT
+        https://bugs.webkit.org/show_bug.cgi?id=207244
+        <rdar://problem/58821709>
+
+        Reviewed by Simon Fraser.
+
+        CTFontTransformGlyphsWithLanguage() is only acceptable on certain OSes.
+
+        * wtf/PlatformHave.h:
+
 2020-02-06  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r255910, r255970, and r255972.

Modified: trunk/Source/WTF/wtf/PlatformHave.h (255987 => 255988)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-02-06 23:31:17 UTC (rev 255988)
@@ -462,10 +462,6 @@
 #define HAVE_CTFONTCREATEFORCHARACTERSWITHLANGUAGEANDOPTION 1
 #endif
 
-#if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-#define HAVE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
-#endif
-
 #if PLATFORM(IOS) || PLATFORM(MACCATALYST)
 #define HAVE_ARKIT_QUICK_LOOK_PREVIEW_ITEM 1
 #endif

Modified: trunk/Source/WTF/wtf/PlatformUse.h (255987 => 255988)


--- trunk/Source/WTF/wtf/PlatformUse.h	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WTF/wtf/PlatformUse.h	2020-02-06 23:31:17 UTC (rev 255988)
@@ -311,3 +311,7 @@
 #if OS(DARWIN) && !USE(PLATFORM_REGISTERS_WITH_PROFILE) && CPU(ARM64)
 #define USE_DARWIN_REGISTER_MACROS 1
 #endif
+
+#if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101600)
+#define USE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
+#endif

Modified: trunk/Source/WebCore/ChangeLog (255987 => 255988)


--- trunk/Source/WebCore/ChangeLog	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/ChangeLog	2020-02-06 23:31:17 UTC (rev 255988)
@@ -1,3 +1,32 @@
+2020-02-06  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        REGRESSION(r254534): 1-3% regression on PLT
+        https://bugs.webkit.org/show_bug.cgi?id=207244
+        <rdar://problem/58821709>
+
+        Reviewed by Simon Fraser.
+
+        Turns out CTFontTransformGlyphsWithLanguage() is 33.7% slower than CTFontTransformGlyphs() on some OSes.
+        This patch changes the preprocessor guards to not use the function on those OSes.
+        Also, the contract of the function on the more performant OSes requires that the locale name be canonicalized,
+        so this patch implements a canonical locale cache inside LocaleMac.mm. It gets cleared when the low memory
+        warning is fired.
+
+        Marked existing tests as failing.
+
+        * page/cocoa/MemoryReleaseCocoa.mm:
+        (WebCore::platformReleaseMemory):
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::applyTransforms const):
+        * platform/graphics/mac/SimpleFontDataCoreText.cpp:
+        (WebCore::Font::getCFStringAttributes const):
+        * platform/text/mac/LocaleMac.h:
+        * platform/text/mac/LocaleMac.mm:
+        (WebCore::determineLocale):
+        (WebCore::canonicalLocaleMap):
+        (WebCore::LocaleMac::canonicalLanguageIdentifierFromString):
+        (WebCore::LocaleMac::releaseMemory):
+
 2020-02-06  Devin Rousso  <drou...@apple.com>
 
         Web Inspector: show _javascript_ Worker terminated state as an internal property

Modified: trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm (255987 => 255988)


--- trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm	2020-02-06 23:31:17 UTC (rev 255988)
@@ -30,6 +30,7 @@
 #import "GCController.h"
 #import "IOSurfacePool.h"
 #import "LayerPool.h"
+#import "LocaleMac.h"
 #import "SystemFontDatabaseCoreText.h"
 #import <notify.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
@@ -55,6 +56,8 @@
     GSFontPurgeFontCache();
 #endif
 
+    LocaleMac::releaseMemory();
+
     for (auto& pool : LayerPool::allLayerPools())
         pool->drain();
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (255987 => 255988)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2020-02-06 23:31:17 UTC (rev 255988)
@@ -32,6 +32,7 @@
 #import "FontCache.h"
 #import "FontCascade.h"
 #import "FontDescription.h"
+#import "LocaleMac.h"
 #import "OpenTypeCG.h"
 #import "SharedBuffer.h"
 #import <CoreText/CoreText.h>
@@ -547,7 +548,7 @@
 {
     // FIXME: Implement GlyphBuffer initial advance.
     CTFontTransformOptions options = (enableKerning ? kCTFontTransformApplyPositioning : 0) | (requiresShaping ? kCTFontTransformApplyShaping : 0);
-#if HAVE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE)
+#if USE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE)
     auto handler = ^(CFRange range, CGGlyph** newGlyphsPointer, CGSize** newAdvancesPointer) {
         range.location = std::min(std::max(range.location, static_cast<CFIndex>(0)), static_cast<CFIndex>(glyphBuffer.size()));
         if (range.length < 0) {
@@ -559,7 +560,7 @@
         *newGlyphsPointer = glyphBuffer.glyphs(beginningIndex);
         *newAdvancesPointer = glyphBuffer.advances(beginningIndex);
     };
-    CTFontTransformGlyphsWithLanguage(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options, locale.string().createCFString().get(), handler);
+    CTFontTransformGlyphsWithLanguage(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options, LocaleMac::canonicalLanguageIdentifierFromString(locale).string().createCFString().get(), handler);
 #else
     UNUSED_PARAM(locale);
     CTFontTransformGlyphs(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options);

Modified: trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp (255987 => 255988)


--- trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp	2020-02-06 23:31:17 UTC (rev 255988)
@@ -37,7 +37,7 @@
     auto attributesDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
 
     CFDictionarySetValue(attributesDictionary.get(), kCTFontAttributeName, platformData().ctFont());
-#if HAVE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE)
+#if USE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE)
     if (!locale.isEmpty())
         CFDictionarySetValue(attributesDictionary.get(), kCTLanguageAttributeName, locale.string().createCFString().get());
 #else

Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (255987 => 255988)


--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h	2020-02-06 23:31:17 UTC (rev 255988)
@@ -67,6 +67,9 @@
     const Vector<String>& timeAMPMLabels() override;
 #endif
 
+    static AtomString canonicalLanguageIdentifierFromString(const AtomString&);
+    static void releaseMemory();
+
 private:
     RetainPtr<NSDateFormatter> shortDateFormatter();
     void initializeLocaleData() override;

Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (255987 => 255988)


--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2020-02-06 23:25:01 UTC (rev 255987)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2020-02-06 23:31:17 UTC (rev 255988)
@@ -35,8 +35,10 @@
 #import <Foundation/NSDateFormatter.h>
 #import <Foundation/NSLocale.h>
 #import <wtf/DateMath.h>
+#import <wtf/HashMap.h>
 #import <wtf/Language.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/text/AtomStringHash.h>
 
 #if PLATFORM(IOS_FAMILY)
 #import "LocalizedDateCache.h"
@@ -62,7 +64,7 @@
     if (equalIgnoringASCIICase(currentLocaleLanguage, localeLanguage))
         return currentLocale;
     // It seems initWithLocaleIdentifier accepts dash-separated locale identifier.
-     return adoptNS([[NSLocale alloc] initWithLocaleIdentifier:locale]);
+    return adoptNS([[NSLocale alloc] initWithLocaleIdentifier:locale]);
 }
 
 std::unique_ptr<Locale> Locale::create(const AtomString& locale)
@@ -276,6 +278,26 @@
 
 #endif
 
+using CanonicalLocaleMap = HashMap<AtomString, AtomString>;
+
+static CanonicalLocaleMap& canonicalLocaleMap()
+{
+    static NeverDestroyed<CanonicalLocaleMap> canonicalLocaleMap;
+    return canonicalLocaleMap.get();
+}
+
+AtomString LocaleMac::canonicalLanguageIdentifierFromString(const AtomString& string)
+{
+    return canonicalLocaleMap().ensure(string, [&] {
+        return [NSLocale canonicalLanguageIdentifierFromString:string];
+    }).iterator->value;
+}
+
+void LocaleMac::releaseMemory()
+{
+    canonicalLocaleMap().clear();
+}
+
 void LocaleMac::initializeLocaleData()
 {
     if (m_didInitializeNumberData)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to