[Cocoa] Improve performance of font lookups
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jul 2017 23:04:18 +0000 (23:04 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jul 2017 23:04:18 +0000 (23:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173960
<rdar://problem/31996891>

Reviewed by Darin Adler.

PerformanceTests:

* Layout/font-fallback-font-family.html: Added.
* Layout/resources/font-fallback-font-family.html: Added.

Source/WebCore:

Looking up kCTFontPostScriptNameAttribute is faster than kCTFontNameAttribute.

No new tests because there is no behavior change.

* platform/spi/cocoa/CoreTextSPI.h:
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontDatabase::fontForPostScriptName):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219223 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/ChangeLog
PerformanceTests/Layout/font-fallback-font-family.html [new file with mode: 0644]
PerformanceTests/Layout/resources/font-fallback-font-family.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/spi/cocoa/CoreTextSPI.h

index 28cb973..e2d9553 100644 (file)
@@ -1,3 +1,14 @@
+2017-07-06  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Improve performance of font lookups
+        https://bugs.webkit.org/show_bug.cgi?id=173960
+        <rdar://problem/31996891>
+
+        Reviewed by Darin Adler.
+
+        * Layout/font-fallback-font-family.html: Added.
+        * Layout/resources/font-fallback-font-family.html: Added.
+
 2017-06-10  Dan Bernstein  <mitz@apple.com>
 
         Reverted r218056 because it made the IDE reindex constantly.
diff --git a/PerformanceTests/Layout/font-fallback-font-family.html b/PerformanceTests/Layout/font-fallback-font-family.html
new file mode 100644 (file)
index 0000000..a934788
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+<script src="../resources/runner.js"></script>
+<script>
+window.onload = function() {
+    PerfTestRunner.measurePageLoadTime({path: "resources/font-fallback-font-family.html"});
+}
+</script>
+</body>
diff --git a/PerformanceTests/Layout/resources/font-fallback-font-family.html b/PerformanceTests/Layout/resources/font-fallback-font-family.html
new file mode 100644 (file)
index 0000000..7f30ab7
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div>
+<script>
+if (window.internals)
+    window.internals.invalidateFontCache();
+const fonts="Times New Roman CYR;Arial CYR;Courier New CYR;\u5b8b\u4f53;Arial Cyr;Times New Roman Cyr;Courier New Cyr;\u534e\u6587\u7ec6\u9ed1;\u5137\u9ed1 Pro;WP CyrillicB;WP CyrillicA;\uad81\uc11c\uccb4;\u7d30\u660e\u9ad4;\u5c0f\u585a\u660e\u671d Pr6N B;\u5b8b\u4f53-PUA;\u65b9\u6b63\u6d41\u884c\u4f53\u7e41\u4f53;\u6c49\u4eea\u5a03\u5a03\u7bc6\u7b80;\ub3cb\uc6c0;GaramondNo4CyrTCYLig;HelveticaInseratCyr Upright;HelveticaCyr Upright;TL Help Cyrillic;\uac00\ub294\uc548\uc0c1\uc218\uccb4;TLCyrillic2;AGRevueCyr-Roman;AGOptimaCyr;HelveticaInseratCyrillicUpright;HelveticaCyrillicUpright;HelveticaCyrillic;CyrillicRibbon;CyrillicHover;\u6587\u9f0e\uff30\uff2f\uff30\uff0d\uff14;\u65b9\u6b63\u4e2d\u5029\u7b80\u4f53;\u521b\u827a\u7b80\u4e2d\u5706;Zrnic Cyr;Zipper1 Cyr;Xorx_windy Cyr;Xorx_Toothy Cyr;\uc18c\uc57c\uc1949;\u0426\u0432\u0435\u0442\u043d\u044b\u0435 \u044d\u043c\u043e\u0434\u0437\u0438 Apple;Chinese Generic1;Korean Generic1;Bullets 5(Korean);UkrainianFuturisExtra;VNI-Viettay;UkrainianCompact;UkrainianBrushScript;TiffanyUkraine;Baltica_Russian-ITV;Vietnamese font;Unicorn Ukrainian;UkrainianTimesET;UkrainianCourier;Tiff-HeavyUkraine;\u4875\u6e67\u4c61\u6e20\u4172\u7464\u6573\u6967\u6e20\u3230\u3032\u202d\u2041\u6c6c\u2072\u6967\u6874\u7320\u7265\u7365\u7276\u6564\u2e54\u6875\u2070\u6861\u7020\u564e\u5468\u7566\u6170\u3032\u2020\u4e6f\u726d\u616c\u312e\u3020\u436f\u6465\u2056\u4e49\u2066\u6f72\u2057\u696e\u646f\u7773\u5468\u7566\u6170\u3032\u4e6f\u726d\u616cHungLan Artdesign - http://www.vietcomic.comVNI-Thufap2  Normalv2.0 Code VNI for WindowsVNI-Thufap2 Normal\u0002;Vietnam;Bwviet;Soviet;Soviet Expanded;Soviet Bold;Russian;UVN Han Viet;UkrainianAcademy;Symbol;Verdana;Webdings;Arial;Georgia;Courier New;Trebuchet MS;Times New Roman;Impact;Comic Sans MS;Wingdings;Tahoma;Microsoft Sans Serif;Arial Black;Plantagenet Cherokee;Arial Narrow;Wingdings 2;Wingdings 3;Arial Unicode MS;Papyrus;Calibri;Cambria;Consolas;Candara;Franklin Gothic Medium;Corbel;Constantia;Marlett;Lucida Console;Lucida Sans Unicode;MS Mincho;Arial Rounded MT Bold;Palatino Linotype;Batang;MS Gothic;PMingLiU;SimSun;MS PGothic;MS PMincho;Gulim;Cambria Math;Garamond;Bookman Old Style;Book Antiqua;Century Gothic;Monotype Corsiva;Courier;Meiryo;Century;MT Extra;MS Reference Sans Serif;MS Reference Specialty;Mistral;Bookshelf Symbol 7;Lucida Bright;Cooper Black;Modern No. 20;Bernard MT Condensed;Bell MT;Baskerville Old Face;Bauhaus 93;Britannic Bold;Wide Latin;Playbill;Harrington;Onyx;Footlight MT Light;Stencil;Colonna MT;Matura MT Script Capitals;Copperplate Gothic Bold;Copperplate Gothic Light;Edwardian Script ITC;Rockwell;Curlz MT;Engravers MT;Rockwell Extra Bold;Haettenschweiler;MingLiU;Mongolian Baiti;Microsoft Yi Baiti;Microsoft Himalaya;SimHei;SimSun-ExtB;PMingLiU-ExtB;MingLiU-ExtB;MingLiU_HKSCS-ExtB;MingLiU_HKSCS;Gabriola;Goudy Old Style;Calisto MT;Imprint MT Shadow;Gill Sans Ultra Bold;Century Schoolbook;Gloucester MT Extra Condensed;Perpetua;Franklin Gothic Book;Brush Script MT;Microsoft Tai Le;Gill Sans MT;Tw Cen MT;Lucida Handwriting;Lucida Sans;Segoe UI;Lucida Fax;MV Boli;Sylfaen;Estrangelo Edessa;Mangal;Gautami;Tunga;Shruti;Raavi;Latha;Lucida Calligraphy;Lucida Sans Typewriter;Kartika;Vrinda;Perpetua Titling MT;Cordia New;Angsana New;IrisUPC;CordiaUPC;FreesiaUPC;Miriam;Traditional Arabic;Miriam Fixed;JasmineUPC;KodchiangUPC;LilyUPC;Levenim MT;EucrosiaUPC;DilleniaUPC;Rod;Narkisim;FrankRuehl;David;Andalus;Browallia New;AngsanaUPC;BrowalliaUPC;MS UI Gothic;Aharoni;Simplified Arabic Fixed;Simplified Arabic;GulimChe;Dotum;DotumChe;GungsuhChe;Gungsuh;BatangChe;Meiryo UI;NSimSun;Segoe Script;Segoe Print;DaunPenh;Kalinga;Iskoola Pota;Euphemia;DokChampa;Nyala;MoolBoran;Leelawadee;Gisha;Microsoft Uighur;Arabic Typesetting;Malgun Gothic;Microsoft JhengHei;DFKai-SB;Microsoft YaHei;FangSong;KaiTi;Helvetica;Segoe UI Light;Segoe UI Semibold;Andale Mono;Palatino;Geneva;Monaco;Lucida Grande;Gill Sans;Helvetica Neue;Baskerville;Hoefler Text;Thonburi;Herculanum;Apple Chancery;Didot;Zapf Dingbats;Apple Symbols;Copperplate;American Typewriter;Zapfino;Cochin;Chalkboard;Sathu;Osaka;BiauKai;Segoe UI Symbol;Aparajita;Krungthep;Ebrima;Silom;Kokila;Shonar Bangla;Sakkal Majalla;Microsoft PhagsPa;Microsoft New Tai Lue;Khmer UI;Vijaya;Utsaah;Charcoal CY;Ayuthaya;InaiMathi;Euphemia UCAS;Vani;Lao UI;GB18030 Bitmap;KufiStandardGK;Geeza Pro;Chalkduster;Tempus Sans ITC;Kristen ITC;Apple Braille;Juice ITC;STHeiti;LiHei Pro;DecoType Naskh;New Peninim MT;Nadeem;Mshtakan;Gujarati MT;Devanagari MT;Arial Hebrew;Corsiva Hebrew;Baghdad;STFangsong".split(";");
+
+for (const f of fonts) {
+    const span = document.createElement('span');
+    span.setAttribute("style",`font-size: 72px; font-family: '${f}', serif;`)
+    span.innerHTML = "mmmmmmmmmmlli";
+    test.appendChild(span);
+    span.offsetWidth;
+    span.remove();
+}
+</script>
+</div>
+</body>
index e7843c3..1131c13 100644 (file)
@@ -1,5 +1,21 @@
 2017-07-06  Myles C. Maxfield  <mmaxfield@apple.com>
 
+        [Cocoa] Improve performance of font lookups
+        https://bugs.webkit.org/show_bug.cgi?id=173960
+        <rdar://problem/31996891>
+
+        Reviewed by Darin Adler.
+
+        Looking up kCTFontPostScriptNameAttribute is faster than kCTFontNameAttribute.
+
+        No new tests because there is no behavior change.
+
+        * platform/spi/cocoa/CoreTextSPI.h:
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontDatabase::fontForPostScriptName):
+
+2017-07-06  Myles C. Maxfield  <mmaxfield@apple.com>
+
         REGRESSION(r216944): Font loads can cause Chinese characters to draw as .notdef
         https://bugs.webkit.org/show_bug.cgi?id=173962
         <rdar://problem/32925318>
index 36e3d2b..86f7de4 100644 (file)
@@ -910,7 +910,12 @@ public:
         auto folded = postScriptName.string().foldCase();
         return m_postScriptNameToFontDescriptors.ensure(folded, [&] {
             auto postScriptNameString = folded.createCFString();
-            CFTypeRef keys[] = { kCTFontEnabledAttribute, kCTFontNameAttribute };
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+            CFStringRef nameAttribute = kCTFontPostScriptNameAttribute;
+#else
+            CFStringRef nameAttribute = kCTFontNameAttribute;
+#endif
+            CFTypeRef keys[] = { kCTFontEnabledAttribute, nameAttribute };
             CFTypeRef values[] = { kCFBooleanTrue, postScriptNameString.get() };
             auto attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
             auto fontDescriptorToMatch = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
index e59f8dc..3a559a7 100644 (file)
@@ -67,6 +67,7 @@ typedef void (*CTUniCharDisposeCallback)(const UniChar* chars, void* refCon);
 
 extern const CFStringRef kCTFontReferenceURLAttribute;
 extern const CFStringRef kCTFontOpticalSizeAttribute;
+extern const CFStringRef kCTFontPostScriptNameAttribute;
 
 bool CTFontTransformGlyphs(CTFontRef, CGGlyph glyphs[], CGSize advances[], CFIndex count, CTFontTransformOptions);