Bug 207244 - REGRESSION(r254534): 1-3% regression on PLT
Summary: REGRESSION(r254534): 1-3% regression on PLT
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-02-04 17:58 PST by Myles C. Maxfield
Modified: 2020-02-07 10:58 PST (History)
13 users (show)

See Also:


Attachments
Patch (6.90 KB, patch)
2020-02-04 18:01 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (6.90 KB, patch)
2020-02-04 18:04 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (7.24 KB, patch)
2020-02-04 19:20 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (12.61 KB, patch)
2020-02-05 17:40 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (12.07 KB, patch)
2020-02-05 17:43 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (12.08 KB, patch)
2020-02-05 17:46 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch for committing (12.49 KB, patch)
2020-02-06 12:19 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch for committing (12.47 KB, patch)
2020-02-06 13:36 PST, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (1.37 KB, patch)
2020-02-06 20:47 PST, Myles C. Maxfield
wenson_hsieh: review+
commit-queue: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2020-02-04 17:58:53 PST
REGRESSION(r254534): 1-3% regression on PLT
Comment 1 Myles C. Maxfield 2020-02-04 18:01:21 PST
Created attachment 389757 [details]
Patch
Comment 2 Myles C. Maxfield 2020-02-04 18:04:01 PST
Created attachment 389758 [details]
Patch
Comment 3 Myles C. Maxfield 2020-02-04 18:04:21 PST
<rdar://problem/58821709>
Comment 4 Simon Fraser (smfr) 2020-02-04 18:09:06 PST
Comment on attachment 389758 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        This is a partial revert of the regressing patch.

Please clarify that it's a full behavior revert, and a partial code revert.

> Source/WTF/wtf/PlatformHave.h:466
>  #define HAVE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1

Maybe just #define to 0

> Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp:48
> +        paragraphStyle = adoptCF(CTParagraphStyleCreate(nullptr, 0));

Here adoptCF makes a temporary RetainPtr but it's then destroyed, so paragraphStyle is left with a pointer to a deleted object.
Comment 5 Myles C. Maxfield 2020-02-04 19:20:34 PST
Created attachment 389760 [details]
Patch
Comment 6 Darin Adler 2020-02-04 20:02:05 PST
Comment on attachment 389760 [details]
Patch

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

> Source/WTF/wtf/PlatformHave.h:467
>  #if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
> -#define HAVE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
> +#define HAVE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 0
>  #endif

This doesn’t seem quite right. We have changed our behavior by deciding not to use this because it’s not fast enough. That doesn’t mean we don’t have it.

Claiming we don’t have it seems like a confusing shortcut. I’d rather see a change at the two call sites even if it’s about commenting out the HAVE and replacing it with a 0 and a comment explaining why. Or you could do something cute and change HAVE to USE at those call sites, knowing that USE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE) will be false.

> Source/WebCore/platform/graphics/FontCascade.cpp:-432
> -    Vector<GlyphBufferGlyph, 16> glyphs;
> -    Vector<GlyphBufferAdvance, 16> advances;

Removing these unused vectors seems like an unrelated change. Not sure why it’s in this patch. Might be a tiny speedup, but seems to slightly muddy the waters about the roll-out.

> Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp:51
> -    auto paragraphStyle = adoptCF(CTParagraphStyleCreate(nullptr, 0));
> -    CTParagraphStyleSetCompositionLanguage(paragraphStyle.get(), kCTCompositionLanguageNone);
> -    CFDictionarySetValue(attributesDictionary.get(), kCTParagraphStyleAttributeName, paragraphStyle.get());
> +    static CTParagraphStyleRef paragraphStyle = nullptr;
> +    if (!paragraphStyle) {
> +        paragraphStyle = CTParagraphStyleCreate(nullptr, 0);
> +        CTParagraphStyleSetCompositionLanguage(paragraphStyle, kCTCompositionLanguageNone);
> +    }
> +    CFDictionarySetValue(attributesDictionary.get(), kCTParagraphStyleAttributeName, paragraphStyle);

Two thoughts.

First, it seems unlikely that this small optimization is part of the revert. Seems like a good idea, but strange to mix it in with the the revert. Same thought as above about muddying the waters.

Second, if there *is* an issue with performance in this function, I suggest that we rewrite it to use CFDictionaryCreate instead of CFDictionaryCreateMutable. It would not be hard at all to assemble the keys and values in two fixed size arrays and then call CFDictionaryCreate at the end. That should be more efficient than a sequence of calls to CFDictionarySetValue, and also save a bit of memory. And also, if it’s called a lot on the same arguments maybe we should cache one or more recently created dictionaries to avoid re-creating them ever time; could use a TinyLRUCache or something like that.
Comment 7 Myles C. Maxfield 2020-02-05 17:40:37 PST
Created attachment 389915 [details]
Patch
Comment 8 Myles C. Maxfield 2020-02-05 17:43:58 PST
Created attachment 389916 [details]
Patch
Comment 9 Myles C. Maxfield 2020-02-05 17:44:33 PST
Comment on attachment 389916 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        This patch changes the preprocessor guards to only use the function on those OSes.

to *not* use
Comment 10 Myles C. Maxfield 2020-02-05 17:46:06 PST
Created attachment 389919 [details]
Patch
Comment 11 Simon Fraser (smfr) 2020-02-05 17:49:43 PST
Comment on attachment 389919 [details]
Patch

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

> Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm:59
> +    LocaleMac::releaseMemory();

Is LocaleMac really LocaleCocoa?
Comment 12 Darin Adler 2020-02-05 19:05:04 PST
Comment on attachment 389919 [details]
Patch

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

> Source/WTF/wtf/PlatformHave.h:467
> -#if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
> -#define HAVE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
> +#if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101600)
> +#define HAVE_ACCEPTABLE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
>  #endif

Are you intentionally turning HAVE_ACCEPTABLE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE on for all iOS family platforms?

Also, I think we should just move this to PlatformUse.h and make it USE(CTFONTTRANSFORMGLYPHSWITHLANGUAGE). Not necessary in this patch, but would be better.

>> Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm:59
>> +    LocaleMac::releaseMemory();
> 
> Is LocaleMac really LocaleCocoa?

It is. Worth renaming soon. Doesn’t seem necessary to do it in this patch.

> Source/WebCore/platform/text/mac/LocaleMac.h:70
> +    static String canonicalLanguageIdentifierFromString(const AtomString&);

Why not have the result also be an AtomString? Could save a little memory for identical strings, and since we’re keeping them in a map, the extra AtomString table lookup cost would be spent only the first time.
Comment 13 Myles C. Maxfield 2020-02-06 11:58:15 PST
(In reply to Darin Adler from comment #12)
> Are you intentionally turning
> HAVE_ACCEPTABLE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE on for all iOS family
> platforms?

Yes. It should never have been off for those platforms.

It looks like either r254676 disabled it for those platforms, or I don't understand the interaction between PLATFORM(IOS_FAMILY) and __IPHONE_OS_VERSION_MIN_REQUIRED. (Probably the latter.)
Comment 14 Myles C. Maxfield 2020-02-06 12:09:56 PST
(In reply to Myles C. Maxfield from comment #13)
> (In reply to Darin Adler from comment #12)
> > Are you intentionally turning
> > HAVE_ACCEPTABLE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE on for all iOS family
> > platforms?
> 
> Yes. It should never have been off for those platforms.
> 
> It looks like either r254676 disabled it for those platforms, or I don't
> understand the interaction between PLATFORM(IOS_FAMILY) and
> __IPHONE_OS_VERSION_MIN_REQUIRED. (Probably the latter.)

After asking some experts, it turns out I don't understand the interaction between PLATFORM(IOS_FAMILY) and __IPHONE_OS_VERSION_MIN_REQUIRED.
Comment 15 Myles C. Maxfield 2020-02-06 12:19:47 PST
Created attachment 389979 [details]
Patch for committing
Comment 16 Myles C. Maxfield 2020-02-06 13:36:27 PST
Created attachment 389987 [details]
Patch for committing
Comment 17 WebKit Commit Bot 2020-02-06 15:30:42 PST
The commit-queue encountered the following flaky tests while processing attachment 389987 [details]:

editing/spelling/spellcheck-async-remove-frame.html bug 158401 (authors: morrita@google.com, rniwa@webkit.org, and tony@chromium.org)
imported/w3c/web-platform-tests/web-animations/timing-model/timelines/update-and-send-events-replacement.html bug 207335 (author: graouts@apple.com)
The commit-queue is continuing to process your patch.
Comment 18 WebKit Commit Bot 2020-02-06 15:31:23 PST
Comment on attachment 389987 [details]
Patch for committing

Clearing flags on attachment: 389987

Committed r255988: <https://trac.webkit.org/changeset/255988>
Comment 19 Myles C. Maxfield 2020-02-06 19:26:13 PST
Comment on attachment 389760 [details]
Patch

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

>> Source/WebCore/platform/graphics/FontCascade.cpp:-432
>> -    Vector<GlyphBufferAdvance, 16> advances;
> 
> Removing these unused vectors seems like an unrelated change. Not sure why it’s in this patch. Might be a tiny speedup, but seems to slightly muddy the waters about the roll-out.

https://bugs.webkit.org/show_bug.cgi?id=207374

>> Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp:51
>> +    CFDictionarySetValue(attributesDictionary.get(), kCTParagraphStyleAttributeName, paragraphStyle);
> 
> Two thoughts.
> 
> First, it seems unlikely that this small optimization is part of the revert. Seems like a good idea, but strange to mix it in with the the revert. Same thought as above about muddying the waters.
> 
> Second, if there *is* an issue with performance in this function, I suggest that we rewrite it to use CFDictionaryCreate instead of CFDictionaryCreateMutable. It would not be hard at all to assemble the keys and values in two fixed size arrays and then call CFDictionaryCreate at the end. That should be more efficient than a sequence of calls to CFDictionarySetValue, and also save a bit of memory. And also, if it’s called a lot on the same arguments maybe we should cache one or more recently created dictionaries to avoid re-creating them ever time; could use a TinyLRUCache or something like that.

https://bugs.webkit.org/show_bug.cgi?id=207374
Comment 20 Myles C. Maxfield 2020-02-06 19:26:48 PST
Comment on attachment 389919 [details]
Patch

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

>>> Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm:59
>>> +    LocaleMac::releaseMemory();
>> 
>> Is LocaleMac really LocaleCocoa?
> 
> It is. Worth renaming soon. Doesn’t seem necessary to do it in this patch.

https://bugs.webkit.org/show_bug.cgi?id=207371
Comment 21 Myles C. Maxfield 2020-02-06 20:36:11 PST
Fixing this patch now.
Comment 22 Myles C. Maxfield 2020-02-06 20:47:29 PST
Reopening to attach new patch.
Comment 23 Myles C. Maxfield 2020-02-06 20:47:30 PST
Created attachment 390053 [details]
Patch
Comment 24 WebKit Commit Bot 2020-02-06 20:51:09 PST
Comment on attachment 390053 [details]
Patch

Rejecting attachment 390053 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'validate-changelog', '--check-oops', '--non-interactive', 390053, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

/Volumes/Data/EWS/WebKit/Source/WebCore/ChangeLog neither lists a valid reviewer nor contains the string "Unreviewed" or "Rubber stamp" (case insensitive).

Full output: https://webkit-queues.webkit.org/results/13318344
Comment 25 Myles C. Maxfield 2020-02-06 21:19:28 PST
Committed r256008: <https://trac.webkit.org/changeset/256008>
Comment 26 Darin Adler 2020-02-07 09:16:25 PST
(In reply to Myles C. Maxfield from comment #14)
> (In reply to Myles C. Maxfield from comment #13)
> > (In reply to Darin Adler from comment #12)
> > > Are you intentionally turning
> > > HAVE_ACCEPTABLE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE on for all iOS family
> > > platforms?
> > 
> > Yes. It should never have been off for those platforms.
> > 
> > It looks like either r254676 disabled it for those platforms, or I don't
> > understand the interaction between PLATFORM(IOS_FAMILY) and
> > __IPHONE_OS_VERSION_MIN_REQUIRED. (Probably the latter.)
> 
> After asking some experts, it turns out I don't understand the interaction
> between PLATFORM(IOS_FAMILY) and __IPHONE_OS_VERSION_MIN_REQUIRED.

Oh, I realize now that my comment should have been clearer.

I knew that it was probably always a mistake that this was off for watchOS and tvOS, and that eventually we would want to correct that mistake, and I was even thinking that it was probably you who would take care of it.

I’ve been discussing this with Jonathan Bedard while reviewing his patches, and he’s intentionally been preserving these kinds of omissions of tvOS and watchOS that we think are likely accidental. Our philosophy was to rewrite the conditional expressions with idioms that make it explicit and clear they are currently omitted.

What I was driving at was that I felt that if you were doing it now, intentionally, the change log ought to have mentioned it! But I used language that was too oblique.

I’m really happy with the actual patch you landed.
Comment 27 Myles C. Maxfield 2020-02-07 10:58:05 PST
(In reply to Darin Adler from comment #26)
> What I was driving at was that I felt that if you were doing it now,
> intentionally, the change log ought to have mentioned it!

Ah yes, I see. You're right, it should have. Probably too late now though. I'll keep this in mind for the future.