Title: [175290] branches/safari-600.3-branch/Source/WebCore
- Revision
- 175290
- Author
- dburk...@apple.com
- Date
- 2014-10-28 17:27:30 -0700 (Tue, 28 Oct 2014)
Log Message
Merge r174456. <rdar://problem/18640864>
Modified Paths
Diff
Modified: branches/safari-600.3-branch/Source/WebCore/ChangeLog (175289 => 175290)
--- branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-10-29 00:22:49 UTC (rev 175289)
+++ branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-10-29 00:27:30 UTC (rev 175290)
@@ -1,5 +1,43 @@
2014-10-28 Dana Burkart <dburk...@apple.com>
+ Merge r174456. <rdar://problem/18640864>
+
+ 2014-10-08 Christophe Dumez <cdu...@apple.com>
+
+ [Mac] We are spending a lot of time loading fonts when loading weather.com
+ https://bugs.webkit.org/show_bug.cgi?id=137454
+
+ Reviewed by Darin Adler.
+
+ We are spending a lot of time loading fonts when loading weather.com:
+ ~4.2% of WebProcess's cpu time in FontCache::getCachedFrontData().
+ In particular, we are spending a lot of time doing font auto-activation
+ because we don't have the Open Sans fonts installed and weather.com is
+ trying to load those.
+
+ Before this patch, we were doing font auto-activation ~250 times when
+ loading weather.com, even though the site is loading ~10 distinct font
+ families.
+
+ This patch adds a cache of font families we already tried to
+ auto-activate so that we don't try again. This results in ~10 font
+ auto-activations when loading weather.com instead of 250. It reduces
+ the amount of time spent in getCachedFrontData() to 62.6ms from 276ms
+ (4.4x less) when loading weather.com.
+
+ No new tests, no behavior change.
+
+ * platform/graphics/mac/FontCacheMac.mm:
+ (WebCore::shouldAutoActivateFontIfNeeded):
+ (WebCore::FontCache::createFontPlatformData):
+ * platform/mac/WebFontCache.h:
+ * platform/mac/WebFontCache.mm:
+ (+[WebFontCache fontWithFamily:traits:weight:size:shouldAutoActivateIfNeeded:]):
+ (+[WebFontCache fontWithFamily:traits:weight:size:]):
+ (+[WebFontCache fontWithFamily:traits:size:]):
+
+2014-10-28 Dana Burkart <dburk...@apple.com>
+
Merge r174190. <rdar://problem/18640846>
2014-10-01 Chris Dumez <cdu...@apple.com>
Modified: branches/safari-600.3-branch/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (175289 => 175290)
--- branches/safari-600.3-branch/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2014-10-29 00:22:49 UTC (rev 175289)
+++ branches/safari-600.3-branch/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2014-10-29 00:27:30 UTC (rev 175290)
@@ -39,9 +39,11 @@
#import "WebFontCache.h"
#import <AppKit/AppKit.h>
#import <wtf/MainThread.h>
+#import <wtf/NeverDestroyed.h>
#import <wtf/StdLibExtras.h>
+#import <wtf/Threading.h>
+#import <wtf/text/AtomicStringHash.h>
-
namespace WebCore {
// The "void*" parameter makes the function match the prototype for callbacks from callOnMainThread.
@@ -88,6 +90,25 @@
return appKitFontWeight >= 7;
}
+static bool shouldAutoActivateFontIfNeeded(const AtomicString& family)
+{
+#ifndef NDEBUG
+ // This cache is not thread safe so the following assertion is there to
+ // make sure this function is always called from the same thread.
+ static ThreadIdentifier initThreadId = currentThread();
+ ASSERT(currentThread() == initThreadId);
+#endif
+
+ static NeverDestroyed<HashSet<AtomicString>> knownFamilies;
+ static const unsigned maxCacheSize = 128;
+ ASSERT(knownFamilies.get().size() <= maxCacheSize);
+ if (knownFamilies.get().size() == maxCacheSize)
+ knownFamilies.get().remove(knownFamilies.get().begin());
+
+ // Only attempt to auto-activate fonts once for performance reasons.
+ return knownFamilies.get().add(family).isNewEntry;
+}
+
PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length)
{
UChar32 character;
@@ -203,7 +224,7 @@
NSInteger weight = toAppKitFontWeight(fontDescription.weight());
float size = fontDescription.computedPixelSize();
- NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
+ NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size shouldAutoActivateIfNeeded:shouldAutoActivateFontIfNeeded(family)];
if (!nsFont)
return nullptr;
Modified: branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.h (175289 => 175290)
--- branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.h 2014-10-29 00:22:49 UTC (rev 175289)
+++ branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.h 2014-10-29 00:27:30 UTC (rev 175290)
@@ -29,6 +29,7 @@
// This interface exists so that third party products (like Silk) can patch in to an Obj-C method to manipulate WebKit's font caching/substitution.
@interface WebFontCache : NSObject
++ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size shouldAutoActivateIfNeeded:(BOOL)shouldAutoActivateIfNeeded;
+ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size;
+ (void)getTraits:(Vector<unsigned>&)traitsMasks inFamily:(NSString *)desiredFamily;
Modified: branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.mm (175289 => 175290)
--- branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.mm 2014-10-29 00:22:49 UTC (rev 175289)
+++ branches/safari-600.3-branch/Source/WebCore/platform/mac/WebFontCache.mm 2014-10-29 00:27:30 UTC (rev 175290)
@@ -276,10 +276,10 @@
return font;
}
-+ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size
++ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size shouldAutoActivateIfNeeded:(BOOL)shouldAutoActivateIfNeeded
{
NSFont *font = [self internalFontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size];
- if (font)
+ if (font || !shouldAutoActivateIfNeeded)
return font;
// Auto activate the font before looking for it a second time.
@@ -289,10 +289,15 @@
return [self internalFontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size];
}
++ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size
+{
+ return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size shouldAutoActivateIfNeeded:YES];
+}
+
+ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits size:(float)size
{
int desiredWeight = (desiredTraits & NSBoldFontMask) ? 9 : 5;
- return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size];
+ return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size shouldAutoActivateIfNeeded:YES];
}
@end
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes