Bug 190467 - Use finer grained locking in FontDatabase
Summary: Use finer grained locking in FontDatabase
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-10-11 06:26 PDT by Antti Koivisto
Modified: 2018-10-11 11:40 PDT (History)
6 users (show)

See Also:


Attachments
patch (4.50 KB, patch)
2018-10-11 06:32 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2018-10-11 06:26:35 PDT
Constructing a font can take a significant amount of time. We don't need to hold the lock during that.
Comment 1 Antti Koivisto 2018-10-11 06:32:49 PDT
Created attachment 352038 [details]
patch
Comment 2 Alex Christensen 2018-10-11 09:40:02 PDT
Comment on attachment 352038 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=352038&action=review

> Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:-893
> -        std::lock_guard<Lock> locker(m_descriptorMapLock);
> -
>          auto folded = familyName.foldCase();
> -        return m_familyNameToFontDescriptors.ensure(folded, [&] {

Wouldn't moving the lock_guard to after the call to foldCase have the same result?  we could leave the call to ensure as it is.
Comment 3 Antti Koivisto 2018-10-11 11:12:05 PDT
> Wouldn't moving the lock_guard to after the call to foldCase have the same
> result?  we could leave the call to ensure as it is.

No, the lock needs to be free during the CTFont stuff, that's the slow part (but inherently thread safe). 

We lookup the cache with the lock held. If we don't find anything we free the lock and do the CTFont dance. Then we retake the lock to add it to the cache (which might not do anything because other thread might have already added this font).
Comment 4 WebKit Commit Bot 2018-10-11 11:39:12 PDT
Comment on attachment 352038 [details]
patch

Clearing flags on attachment: 352038

Committed r237040: <https://trac.webkit.org/changeset/237040>
Comment 5 WebKit Commit Bot 2018-10-11 11:39:14 PDT
All reviewed patches have been landed.  Closing bug.
Comment 6 Radar WebKit Bug Importer 2018-10-11 11:40:27 PDT
<rdar://problem/45199971>