Title: [232221] trunk
Revision
232221
Author
[email protected]
Date
2018-05-25 20:44:49 -0700 (Fri, 25 May 2018)

Log Message

Improve the performance of Font::canRenderCombiningCharacterSequence()
https://bugs.webkit.org/show_bug.cgi?id=185933

Reviewed by Ryosuke Niwa.

PerformanceTests:

* Layout/ComplexLongUnique.html: Added.

Source/WebCore:

We don't need to create a whole CTLine just to determine whether or not a font supports rendering a grapheme cluster.
Instead, the right way to do it is just see if the font's cmap table supports every code point in the cluster.

This patch reports a 2% progression on the attached PerformanceTest.

Test: Layout/ComplexLongUnique.html

* platform/graphics/Font.cpp:
(WebCore::Font::canRenderCombiningCharacterSequence const):
* platform/graphics/Font.h:
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::provideStringAndAttributes): Deleted.
(WebCore::Font::canRenderCombiningCharacterSequence const): Deleted.
* platform/graphics/freetype/SimpleFontDataFreeType.cpp:
(WebCore::Font::canRenderCombiningCharacterSequence const): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/PerformanceTests/ChangeLog (232220 => 232221)


--- trunk/PerformanceTests/ChangeLog	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/PerformanceTests/ChangeLog	2018-05-26 03:44:49 UTC (rev 232221)
@@ -1,3 +1,12 @@
+2018-05-25  Myles C. Maxfield  <[email protected]>
+
+        Improve the performance of Font::canRenderCombiningCharacterSequence()
+        https://bugs.webkit.org/show_bug.cgi?id=185933
+
+        Reviewed by Ryosuke Niwa.
+
+        * Layout/ComplexLongUnique.html: Added.
+
 2018-05-25  Saam Barati  <[email protected]>
 
         Have a memory test where we can validate JSCs mini memory mode

Added: trunk/PerformanceTests/Layout/ComplexLongUnique.html (0 => 232221)


--- trunk/PerformanceTests/Layout/ComplexLongUnique.html	                        (rev 0)
+++ trunk/PerformanceTests/Layout/ComplexLongUnique.html	2018-05-26 03:44:49 UTC (rev 232221)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<div id="target" style="width: 1000000px; display: none;"></div>
+<script>
+var target = document.getElementById("target");
+var style = target.style;
+
+var s = "e\u0300";
+var length = 10000;
+var startCode = 0x4E00;
+for (var i = 0; i < length; ++i) {
+    s = s + String.fromCharCode(i + startCode) + "\u0300";
+}
+
+function test() {
+    if (window.internals)
+        window.internals.invalidateFontCache();
+
+    style.display = "block";
+    target.offsetLeft;
+    target.textContent = s;
+    target.offsetLeft;
+    target.textContent = "";
+    style.display = "none";
+}
+
+PerfTestRunner.measureRunsPerSecond({ run: test });
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (232220 => 232221)


--- trunk/Source/WebCore/ChangeLog	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/Source/WebCore/ChangeLog	2018-05-26 03:44:49 UTC (rev 232221)
@@ -1,3 +1,26 @@
+2018-05-25  Myles C. Maxfield  <[email protected]>
+
+        Improve the performance of Font::canRenderCombiningCharacterSequence()
+        https://bugs.webkit.org/show_bug.cgi?id=185933
+
+        Reviewed by Ryosuke Niwa.
+
+        We don't need to create a whole CTLine just to determine whether or not a font supports rendering a grapheme cluster.
+        Instead, the right way to do it is just see if the font's cmap table supports every code point in the cluster.
+
+        This patch reports a 2% progression on the attached PerformanceTest.
+
+        Test: Layout/ComplexLongUnique.html
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::canRenderCombiningCharacterSequence const):
+        * platform/graphics/Font.h:
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::provideStringAndAttributes): Deleted.
+        (WebCore::Font::canRenderCombiningCharacterSequence const): Deleted.
+        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
+        (WebCore::Font::canRenderCombiningCharacterSequence const): Deleted.
+
 2018-05-25  Eric Carlson  <[email protected]>
 
         Captions are sized incorrectly in PiP mode

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (232220 => 232221)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2018-05-26 03:44:49 UTC (rev 232221)
@@ -513,4 +513,14 @@
 }
 #endif
 
+bool Font::canRenderCombiningCharacterSequence(const UChar* characters, size_t length) const
+{
+    ASSERT(isMainThread());
+
+    for (UChar32 codePoint : StringView(characters, length).codePoints()) {
+        if (!glyphForCharacter(codePoint))
+            return false;
+    }
+    return true;
+}
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/Font.h (232220 => 232221)


--- trunk/Source/WebCore/platform/graphics/Font.h	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2018-05-26 03:44:49 UTC (rev 232221)
@@ -199,10 +199,7 @@
     const BitVector& glyphsSupportedByAllPetiteCaps() const;
 #endif
 
-#if PLATFORM(COCOA) || USE(HARFBUZZ)
     bool canRenderCombiningCharacterSequence(const UChar*, size_t) const;
-#endif
-
     bool applyTransforms(GlyphBufferGlyph*, GlyphBufferAdvance*, size_t glyphCount, bool enableKerning, bool requiresShaping) const;
 
 #if PLATFORM(WIN)
@@ -297,10 +294,6 @@
     mutable std::optional<BitVector> m_glyphsSupportedByAllPetiteCaps;
 #endif
 
-#if PLATFORM(COCOA) || USE(HARFBUZZ)
-    mutable std::unique_ptr<HashMap<String, bool>> m_combiningCharacterSequenceSupport;
-#endif
-
 #if PLATFORM(WIN)
     mutable SCRIPT_CACHE m_scriptCache;
     mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm	2018-05-26 03:44:49 UTC (rev 232221)
@@ -597,53 +597,4 @@
     return advance.width + m_syntheticBoldOffset;
 }
 
-struct ProviderInfo {
-    const UChar* characters;
-    size_t length;
-    CFDictionaryRef attributes;
-};
-
-static const UniChar* provideStringAndAttributes(CFIndex stringIndex, CFIndex* count, CFDictionaryRef* attributes, void* context)
-{
-    ProviderInfo* info = static_cast<struct ProviderInfo*>(context);
-    if (stringIndex < 0 || static_cast<size_t>(stringIndex) >= info->length)
-        return 0;
-
-    *count = info->length - stringIndex;
-    *attributes = info->attributes;
-    return info->characters + stringIndex;
-}
-
-bool Font::canRenderCombiningCharacterSequence(const UChar* characters, size_t length) const
-{
-    ASSERT(isMainThread());
-
-    if (!m_combiningCharacterSequenceSupport)
-        m_combiningCharacterSequenceSupport = std::make_unique<HashMap<String, bool>>();
-
-    WTF::HashMap<String, bool>::AddResult addResult = m_combiningCharacterSequenceSupport->add(String(characters, length), false);
-    if (!addResult.isNewEntry)
-        return addResult.iterator->value;
-
-    RetainPtr<CFTypeRef> fontEqualityObject = platformData().objectForEqualityCheck();
-
-    ProviderInfo info = { characters, length, getCFStringAttributes(false, platformData().orientation()) };
-    RetainPtr<CTLineRef> line = adoptCF(CTLineCreateWithUniCharProvider(&provideStringAndAttributes, 0, &info));
-
-    CFArrayRef runArray = CTLineGetGlyphRuns(line.get());
-    CFIndex runCount = CFArrayGetCount(runArray);
-
-    for (CFIndex r = 0; r < runCount; r++) {
-        CTRunRef ctRun = static_cast<CTRunRef>(CFArrayGetValueAtIndex(runArray, r));
-        ASSERT(CFGetTypeID(ctRun) == CTRunGetTypeID());
-        CFDictionaryRef runAttributes = CTRunGetAttributes(ctRun);
-        CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttributes, kCTFontAttributeName));
-        if (!CFEqual(fontEqualityObject.get(), FontPlatformData::objectForEqualityCheck(runFont).get()))
-            return false;
-    }
-
-    addResult.iterator->value = true;
-    return true;
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp (232220 => 232221)


--- trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp	2018-05-26 01:02:44 UTC (rev 232220)
+++ trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp	2018-05-26 03:44:49 UTC (rev 232221)
@@ -187,45 +187,4 @@
     return width ? width : m_spaceWidth;
 }
 
-#if USE(HARFBUZZ)
-bool Font::canRenderCombiningCharacterSequence(const UChar* characters, size_t length) const
-{
-    if (!m_combiningCharacterSequenceSupport)
-        m_combiningCharacterSequenceSupport = std::make_unique<HashMap<String, bool>>();
-
-    WTF::HashMap<String, bool>::AddResult addResult = m_combiningCharacterSequenceSupport->add(String(characters, length), false);
-    if (!addResult.isNewEntry)
-        return addResult.iterator->value;
-
-    UErrorCode error = U_ZERO_ERROR;
-    Vector<UChar, 4> normalizedCharacters(length);
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-    int32_t normalizedLength = unorm_normalize(characters, length, UNORM_NFC, UNORM_UNICODE_3_2, &normalizedCharacters[0], length, &error);
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic pop
-#endif
-    if (U_FAILURE(error))
-        return false;
-
-    CairoFtFaceLocker cairoFtFaceLocker(m_platformData.scaledFont());
-    FT_Face face = cairoFtFaceLocker.ftFace();
-    if (!face)
-        return false;
-
-    UChar32 character;
-    unsigned clusterLength = 0;
-    SurrogatePairAwareTextIterator iterator(normalizedCharacters.data(), 0, normalizedLength, normalizedLength);
-    for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) {
-        if (!FcFreeTypeCharIndex(face, character))
-            return false;
-    }
-
-    addResult.iterator->value = true;
-    return true;
 }
-#endif
-
-}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to