Bug 211223 - Some HTML element critical paths include AtomString materialization
Summary: Some HTML element critical paths include AtomString materialization
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-29 22:55 PDT by Yusuke Suzuki
Modified: 2020-05-11 11:25 PDT (History)
14 users (show)

See Also:


Attachments
Patch (33.21 KB, patch)
2020-04-30 15:45 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (33.21 KB, patch)
2020-04-30 15:52 PDT, Yusuke Suzuki
saam: review+
Details | Formatted Diff | Diff
Patch (33.96 KB, patch)
2020-04-30 16:30 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-04-29 22:55:17 PDT
We should use `static NeverDestroyed<AtomString>`.
Comment 1 Yusuke Suzuki 2020-04-30 15:45:40 PDT
Created attachment 398107 [details]
Patch
Comment 2 Yusuke Suzuki 2020-04-30 15:52:14 PDT
Created attachment 398108 [details]
Patch
Comment 3 Saam Barati 2020-04-30 15:58:33 PDT
Comment on attachment 398108 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        `static NeverDestroyed<const AtomString> ...("...", AtomString::ConstructFromLiteral)`. Since HTML is in the main thread, we can just use `static NeverDestroyed<>`.

can you add asserts everywhere you did this that we're on the main thread?
Comment 4 Saam Barati 2020-04-30 16:10:25 PDT
I spoke to Yusuke and this is done everywhere.

My observation is we should have asserts in all those places.

But this patch doesn't need to be the thing adding them.
Comment 5 Yusuke Suzuki 2020-04-30 16:17:37 PDT
(In reply to Saam Barati from comment #4)
> I spoke to Yusuke and this is done everywhere.
> 
> My observation is we should have asserts in all those places.
> 
> But this patch doesn't need to be the thing adding them.

I think we should introduce `MainThreadNeverDestroyed<const AtomString>` and insert `ASSERT(isMainThread());` in get accessor of that class. And replace existing `NeverDestroyed<const AtomString>` with that. But I think this should be done separately given that we already have so many things like that and this patch's goal is not fixing / finding an existing bug with a new abstraction.
Comment 6 Yusuke Suzuki 2020-04-30 16:18:49 PDT
(In reply to Yusuke Suzuki from comment #5)
> (In reply to Saam Barati from comment #4)
> > I spoke to Yusuke and this is done everywhere.
> > 
> > My observation is we should have asserts in all those places.
> > 
> > But this patch doesn't need to be the thing adding them.
> 
> I think we should introduce `MainThreadNeverDestroyed<const AtomString>` and
> insert `ASSERT(isMainThread());` in get accessor of that class. And replace
> existing `NeverDestroyed<const AtomString>` with that. But I think this
> should be done separately given that we already have so many things like
> that and this patch's goal is not fixing / finding an existing bug with a
> new abstraction.

https://bugs.webkit.org/show_bug.cgi?id=211264
Comment 7 Yusuke Suzuki 2020-04-30 16:26:35 PDT
Inserted `ASSERT(isMainThread())` for newly added NeverDestroyed<>. I postpone `isMainThread()` assertion check in the existing places in https://bugs.webkit.org/show_bug.cgi?id=211264.
Comment 8 Yusuke Suzuki 2020-04-30 16:30:53 PDT
Created attachment 398119 [details]
Patch

Patch for landing
Comment 9 Yusuke Suzuki 2020-04-30 18:44:48 PDT
Comment on attachment 398119 [details]
Patch

OK, EWS is green.
Comment 10 EWS 2020-04-30 18:47:52 PDT
Committed r260977: <https://trac.webkit.org/changeset/260977>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398119 [details].
Comment 11 Radar WebKit Bug Importer 2020-04-30 18:48:16 PDT
<rdar://problem/62691779>
Comment 12 Darin Adler 2020-05-10 16:15:33 PDT
Comment on attachment 398108 [details]
Patch

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

>> Source/WebCore/ChangeLog:10
>> +        `static NeverDestroyed<const AtomString> ...("...", AtomString::ConstructFromLiteral)`. Since HTML is in the main thread, we can just use `static NeverDestroyed<>`.
> 
> can you add asserts everywhere you did this that we're on the main thread?

If so, please don’t write each one out. Make a class that does it! Even one specific to AtomString would be OK with me.
Comment 13 Darin Adler 2020-05-10 16:18:08 PDT
Comment on attachment 398119 [details]
Patch

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

> Source/WebCore/html/SearchInputType.cpp:70
> +    ASSERT(isMainThread());

Adding all these asserts like this doesn’t seem good. Tons of DOM code all assumes it’s on the main thread. Adding these assertions everywhere we use an AtomString like this is inelegant and inconsistent with WebKit coding style. The DOM code could be peppered with ASSERT(isMainThread()); that assertion is true/needed throughout.

If we really want these, I suggest we make a class MainThreadAtomStringLiteral:

    static MainThreadAtomStringLiteral webkitSearchResultsButtonName("-webkit-search-results-button");

The assertions would go in the "get" function as well as the construction code.
Comment 14 Yusuke Suzuki 2020-05-11 03:59:17 PDT
Comment on attachment 398119 [details]
Patch

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

>> Source/WebCore/html/SearchInputType.cpp:70
>> +    ASSERT(isMainThread());
> 
> Adding all these asserts like this doesn’t seem good. Tons of DOM code all assumes it’s on the main thread. Adding these assertions everywhere we use an AtomString like this is inelegant and inconsistent with WebKit coding style. The DOM code could be peppered with ASSERT(isMainThread()); that assertion is true/needed throughout.
> 
> If we really want these, I suggest we make a class MainThreadAtomStringLiteral:
> 
>     static MainThreadAtomStringLiteral webkitSearchResultsButtonName("-webkit-search-results-button");
> 
> The assertions would go in the "get" function as well as the construction code.

I already landed MainThreadNeverDestroyed :) https://trac.webkit.org/changeset/261013/webkit

See https://bugs.webkit.org/show_bug.cgi?id=211223#c7 and https://bugs.webkit.org/show_bug.cgi?id=211264
Comment 15 Yusuke Suzuki 2020-05-11 04:05:48 PDT
Comment on attachment 398119 [details]
Patch

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

>>> Source/WebCore/html/SearchInputType.cpp:70
>>> +    ASSERT(isMainThread());
>> 
>> Adding all these asserts like this doesn’t seem good. Tons of DOM code all assumes it’s on the main thread. Adding these assertions everywhere we use an AtomString like this is inelegant and inconsistent with WebKit coding style. The DOM code could be peppered with ASSERT(isMainThread()); that assertion is true/needed throughout.
>> 
>> If we really want these, I suggest we make a class MainThreadAtomStringLiteral:
>> 
>>     static MainThreadAtomStringLiteral webkitSearchResultsButtonName("-webkit-search-results-button");
>> 
>> The assertions would go in the "get" function as well as the construction code.
> 
> I already landed MainThreadNeverDestroyed :) https://trac.webkit.org/changeset/261013/webkit
> 
> See https://bugs.webkit.org/show_bug.cgi?id=211223#c7 and https://bugs.webkit.org/show_bug.cgi?id=211264

And that patch actually found one tricky usage in GTK/WPE ports https://trac.webkit.org/changeset/261075/webkit
Comment 16 Darin Adler 2020-05-11 09:29:15 PDT
(In reply to Yusuke Suzuki from comment #14)
> I already landed MainThreadNeverDestroyed :)
> https://trac.webkit.org/changeset/261013/webkit

Could you use that here instead of adding all these assertions?
Comment 17 Yusuke Suzuki 2020-05-11 11:23:10 PDT
(In reply to Darin Adler from comment #16)
> (In reply to Yusuke Suzuki from comment #14)
> > I already landed MainThreadNeverDestroyed :)
> > https://trac.webkit.org/changeset/261013/webkit
> 
> Could you use that here instead of adding all these assertions?

The patch here is already landed. And https://trac.webkit.org/changeset/261013/webkit is introduced after that, and it replaces inserted `ASSERT(isMainThread())` with `MainThreadNeverDestroyed<>`. So, it is already done :)
Comment 18 Darin Adler 2020-05-11 11:25:54 PDT
(In reply to Yusuke Suzuki from comment #17)
> it replaces inserted `ASSERT(isMainThread())` with
> `MainThreadNeverDestroyed<>`

Great! Sorry I didn’t understand.

I still think that one specifically for AtomString would be nice to make the code less wordy.