Bug 145180

Summary: [Mac] Font lookups are flakey due to caching
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Layout and RenderingAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, mmaxfield
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=145149
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Chris Dumez
Reported 2015-05-19 13:40:34 PDT
Font lookups are flakey due to caching in fontWithFamily(). Radar: <rdar://problem/21012406>
Attachments
Patch (13.52 KB, patch)
2015-05-19 13:51 PDT, Chris Dumez
no flags
Patch (14.53 KB, patch)
2015-05-19 14:24 PDT, Chris Dumez
no flags
Patch (14.36 KB, patch)
2015-05-19 14:25 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2015-05-19 13:51:29 PDT
Darin Adler
Comment 2 2015-05-19 14:01:11 PDT
Comment on attachment 253395 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=253395&action=review > Source/WebCore/ChangeLog:16 > + This patch now uses a std::pair as key containing both the "desired > + family" and the "desired traits" for correctness. I also updated the > + cache to use WTF types instead of NS types. So now looking up a name in the cache requires converting an AtomicString to an NSString every time? That doesn’t seem like an improvement! > Source/WebCore/platform/graphics/mac/FontCacheMac.mm:159 > + familyMapping.add(std::make_pair(desiredFamily, desiredTraits), value); Old code did the equivalent of HashMap::set, not HashMap::add. Is this a desirable change?
Chris Dumez
Comment 3 2015-05-19 14:21:51 PDT
Comment on attachment 253395 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=253395&action=review >> Source/WebCore/ChangeLog:16 >> + cache to use WTF types instead of NS types. > > So now looking up a name in the cache requires converting an AtomicString to an NSString every time? That doesn’t seem like an improvement! Converting an AtomicString into a NSString is relatively cheap. It ends up calling StringImpl::createCFString() which constructs a CFStringRef (later casted to a NSString*) *without* copying the characters. The cost of converting an AtomicString into a NSString* is thus really small compared to calling [fontManager availableFontFamilies] + [fontManager availableFonts] and doing linear searches on those 2 lists. There is a slight overhead when saving a mapping into the cache though because we need to construct an AtomicString for the NSString* of the availableFamily. However, we already get the desiredFamily as an AtomicString so we no longer need to convert it to an NSString* when the cache is successful (I will re-upload an iteration with this optimization). Therefore, it is a win there and also HashMap usually performs better than NSDictionary. >> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:159 >> + familyMapping.add(std::make_pair(desiredFamily, desiredTraits), value); > > Old code did the equivalent of HashMap::set, not HashMap::add. Is this a desirable change? We only call this function if the key is not already present so add() is slightly faster here.
Chris Dumez
Comment 4 2015-05-19 14:24:23 PDT
Chris Dumez
Comment 5 2015-05-19 14:25:48 PDT
WebKit Commit Bot
Comment 6 2015-05-19 15:52:44 PDT
Comment on attachment 253401 [details] Patch Clearing flags on attachment: 253401 Committed r184599: <http://trac.webkit.org/changeset/184599>
WebKit Commit Bot
Comment 7 2015-05-19 15:52:48 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.