Bug 237235 - Optimize StyleSharingResolver inert check
Summary: Optimize StyleSharingResolver inert check
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Nguyen (:ntim)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-26 03:38 PST by Tim Nguyen (:ntim)
Modified: 2022-02-27 07:46 PST (History)
4 users (show)

See Also:


Attachments
Patch (2.50 KB, patch)
2022-02-26 03:40 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff
Patch (2.90 KB, patch)
2022-02-27 00:08 PST, Tim Nguyen (:ntim)
youennf: review+
Details | Formatted Diff | Diff
[fast-cq] Patch (4.91 KB, patch)
2022-02-27 06:08 PST, Tim Nguyen (:ntim)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Nguyen (:ntim) 2022-02-26 03:38:04 PST
readonly & inert are boolean attributes, the only thing that matters is the presence of the attribute, not its value. E.g. `readonly=false` behaves the same as `readonly=readonly` or `readonly=true`.

This saves getting and comparing values for those attributes, and also allows `readonly=readonly` and `readonly=true` or `readonly=false` to start using style sharing.

Same applies for inert.
Comment 1 Tim Nguyen (:ntim) 2022-02-26 03:40:39 PST
Created attachment 453291 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2022-02-26 03:43:56 PST
<rdar://problem/89510628>
Comment 3 Tim Nguyen (:ntim) 2022-02-26 08:13:19 PST
Looks like we can't do this for readonly because of the special isCommonAttributeSelectorAttribute optimization.
Comment 4 Darin Adler 2022-02-26 13:22:44 PST
Comment on attachment 453291 [details]
Patch

Code change looks great. Need to update tests to reflect a progression, I think? I will set review+ once there’s a patch that includes the needed changes to tests.
Comment 5 Darin Adler 2022-02-26 13:23:09 PST
(In reply to Tim Nguyen (:ntim) from comment #3)
> Looks like we can't do this for readonly because of the special
> isCommonAttributeSelectorAttribute optimization.

Oh really? That seems unfortunate. Maybe we can fix that optimization too?
Comment 6 Tim Nguyen (:ntim) 2022-02-27 00:08:18 PST
Created attachment 453327 [details]
Patch
Comment 7 Tim Nguyen (:ntim) 2022-02-27 00:13:03 PST
(In reply to Darin Adler from comment #5)
> (In reply to Tim Nguyen (:ntim) from comment #3)
> > Looks like we can't do this for readonly because of the special
> > isCommonAttributeSelectorAttribute optimization.
> 
> Oh really? That seems unfortunate. Maybe we can fix that optimization too?

The readonly/type attributes are there for different reasons than the inert attribute.

E.g. if we removed readonly/type from `isCommonAttributeSelectorAttribute`, then they wouldn't need this style sharing check.

The inert attribute is there because StyleAdjuster applies different styling based on the inert attribute's presence, and we don't want to wrongly share that styling.

I got it wrong the first time :( I added some comments in the code to avoid this confusion.

(In reply to Darin Adler from comment #4)
> Comment on attachment 453291 [details]
> Patch
> 
> Code change looks great. Need to update tests to reflect a progression, I
> think? I will set review+ once there’s a patch that includes the needed
> changes to tests.

The failures were actually a regression in readonly's style sharing, the tests actually had different styling for [readonly=foo] and [readonly] and we rendered them the same.
Comment 8 youenn fablet 2022-02-27 03:12:12 PST
Comment on attachment 453327 [details]
Patch

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

> Source/WebCore/ChangeLog:13
> +        `inert=inert` and `inert=true` or `inert=false` to start sharing style.

This seems testable, can we add a test?
Comment 9 Tim Nguyen (:ntim) 2022-02-27 03:58:27 PST
Comment on attachment 453327 [details]
Patch

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

>> Source/WebCore/ChangeLog:13
>> +        `inert=inert` and `inert=true` or `inert=false` to start sharing style.
> 
> This seems testable, can we add a test?

style sharing is an optimization, so behavior before/after this patch should be the same, just with different speeds.

I could add tests to make sure the optimization does not break anything though. I'll copy the ones readonly have, and add some inert specific ones too.
Comment 10 Tim Nguyen (:ntim) 2022-02-27 06:08:15 PST
Created attachment 453335 [details]
[fast-cq] Patch
Comment 11 EWS 2022-02-27 06:12:18 PST
Committed r290559 (247837@main): <https://commits.webkit.org/247837@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 453335 [details].
Comment 12 Darin Adler 2022-02-27 07:46:41 PST
(In reply to Tim Nguyen (:ntim) from comment #9)
> style sharing is an optimization, so behavior before/after this patch should
> be the same, just with different speeds.

Important optimizations can be tested too, with tests designed to have dramatically different performance without the optimization. These are valuable and can be important, almost as important as correctness tests, even though they can be more difficult to create.