Bug 206343 - Compact sizeof(HTMLAnchorElement) and sizeof(HTMLLinkElement)
Summary: Compact sizeof(HTMLAnchorElement) and sizeof(HTMLLinkElement)
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: 208162
Blocks:
  Show dependency treegraph
 
Reported: 2020-01-16 02:49 PST by Yusuke Suzuki
Modified: 2020-02-24 17:39 PST (History)
12 users (show)

See Also:


Attachments
Patch (9.70 KB, patch)
2020-01-16 03:01 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (9.84 KB, patch)
2020-01-16 03:05 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (20.15 KB, patch)
2020-01-16 17:40 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (11.50 KB, patch)
2020-01-16 17:53 PST, Yusuke Suzuki
rniwa: review+
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-01-16 02:49:20 PST
I noticed that HTMLAnchorElement is relatively frequently allocated, while it has not squeezed
Comment 1 Yusuke Suzuki 2020-01-16 03:01:03 PST
Created attachment 387902 [details]
Patch
Comment 2 Yusuke Suzuki 2020-01-16 03:05:18 PST
Created attachment 387903 [details]
Patch
Comment 3 Yusuke Suzuki 2020-01-16 17:40:20 PST
Created attachment 387996 [details]
Patch

Uploading just to ensure that SharedStringHash is not modified
Comment 4 Yusuke Suzuki 2020-01-16 17:53:15 PST
Created attachment 387998 [details]
Patch
Comment 5 Yusuke Suzuki 2020-01-16 17:54:08 PST
The first patch is demonstrating that upper 32bit is never used.
Comment 6 Ryosuke Niwa 2020-01-16 23:24:09 PST
No need to say WebCore. It's pretty obvious from class names.
Comment 7 Ryosuke Niwa 2020-01-16 23:27:43 PST
Comment on attachment 387998 [details]
Patch

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

> Source/WebCore/ChangeLog:3
> +        [WebCore] Compact sizeof(HTMLAnchorElement) and sizeof(HTMLLinkElement)

Please correct the bug title in the change log accordingly.
Comment 8 Yusuke Suzuki 2020-01-16 23:28:12 PST
Comment on attachment 387998 [details]
Patch

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

>> Source/WebCore/ChangeLog:3
>> +        [WebCore] Compact sizeof(HTMLAnchorElement) and sizeof(HTMLLinkElement)
> 
> Please correct the bug title in the change log accordingly.

Thanks, fixed.
Comment 9 Yusuke Suzuki 2020-01-16 23:32:15 PST
Committed r254739: <https://trac.webkit.org/changeset/254739>
Comment 10 Radar WebKit Bug Importer 2020-01-16 23:33:20 PST
<rdar://problem/58673446>
Comment 11 Darin Adler 2020-01-17 08:58:13 PST
Comment on attachment 387998 [details]
Patch

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

> Source/WebCore/html/HTMLLinkElement.h:140
>      String m_type;
>      String m_media;
> +    String m_integrityMetadataForPendingSheetRequest;
>      std::unique_ptr<DOMTokenList> m_sizes;
> +    std::unique_ptr<DOMTokenList> m_relList;

Seems like we could make HTMLinkElement significantly smaller given that it has many different purposes and we have separate data members for each of those purposes. Something like the rare data pattern perhaps? Even unclear why we need members like m_type and m_media at all, just to cache computed attribute values.

> Source/WebCore/html/LinkRelAttribute.cpp:45
> +    : iconType()

Why is this needed? It won’t get initialized unless we specify it explicitly? I kind of wish Markable had a side effect of initializing things to zero when constructed. Not sure we have any use cases for scalars that don’t get initialized.
Comment 12 Emilio Cobos Álvarez (:emilio) 2020-01-17 09:13:37 PST
Comment on attachment 387998 [details]
Patch

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

> Source/WebCore/html/HTMLLinkElement.cpp:305
> +            makeScopeExit([&] { m_isHandlingBeforeLoad = previous; });

FWIW, this doesn't look right. This will instantly run the callback, as it's not kept alive by any variable.
Comment 13 Chris Dumez 2020-01-17 09:26:59 PST
Comment on attachment 387998 [details]
Patch

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

>> Source/WebCore/html/HTMLLinkElement.cpp:305
>> +            makeScopeExit([&] { m_isHandlingBeforeLoad = previous; });
> 
> FWIW, this doesn't look right. This will instantly run the callback, as it's not kept alive by any variable.

lol, good catch! Not the first time we get caught by that. The return value of makeScopeExit should really be marked as never ignored.
Comment 14 Chris Dumez 2020-01-17 09:28:32 PST
Comment on attachment 387998 [details]
Patch

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

>>> Source/WebCore/html/HTMLLinkElement.cpp:305
>>> +            makeScopeExit([&] { m_isHandlingBeforeLoad = previous; });
>> 
>> FWIW, this doesn't look right. This will instantly run the callback, as it's not kept alive by any variable.
> 
> lol, good catch! Not the first time we get caught by that. The return value of makeScopeExit should really be marked as never ignored.

I mean WARN_UNUSED_RETURN.
Comment 15 Yusuke Suzuki 2020-02-24 15:44:15 PST
(In reply to Chris Dumez from comment #14)
> Comment on attachment 387998 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=387998&action=review
> 
> >>> Source/WebCore/html/HTMLLinkElement.cpp:305
> >>> +            makeScopeExit([&] { m_isHandlingBeforeLoad = previous; });
> >> 
> >> FWIW, this doesn't look right. This will instantly run the callback, as it's not kept alive by any variable.
> > 
> > lol, good catch! Not the first time we get caught by that. The return value of makeScopeExit should really be marked as never ignored.
> 
> I mean WARN_UNUSED_RETURN.

Oops, nice. I'm creating a patch for this now.
Comment 16 Yusuke Suzuki 2020-02-24 15:51:38 PST
Comment on attachment 387998 [details]
Patch

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

>>>>> Source/WebCore/html/HTMLLinkElement.cpp:305
>>>>> +            makeScopeExit([&] { m_isHandlingBeforeLoad = previous; });
>>>> 
>>>> FWIW, this doesn't look right. This will instantly run the callback, as it's not kept alive by any variable.
>>> 
>>> lol, good catch! Not the first time we get caught by that. The return value of makeScopeExit should really be marked as never ignored.
>> 
>> I mean WARN_UNUSED_RETURN.
> 
> Oops, nice. I'm creating a patch for this now.

Opened for this https://bugs.webkit.org/show_bug.cgi?id=208162