Bug 221319 - Avoid a virtual function call in HTMLFormControlElement::isDisabledOrReadOnly()
Summary: Avoid a virtual function call in HTMLFormControlElement::isDisabledOrReadOnly()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-02 21:51 PST by Simon Fraser (smfr)
Modified: 2021-03-05 00:44 PST (History)
11 users (show)

See Also:


Attachments
Patch (1.72 KB, patch)
2021-02-02 21:53 PST, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2021-02-02 21:51:31 PST
Avoid a virtual function call in HTMLFormControlElement::isDisabledOrReadOnly()
Comment 1 Simon Fraser (smfr) 2021-02-02 21:53:39 PST
Created attachment 419105 [details]
Patch
Comment 2 Ryosuke Niwa 2021-02-02 22:06:34 PST
Comment on attachment 419105 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        Avoid calling isDisabledFormControl() which is a virtual function on Element.
> +        HTMLFormControlElement is the only class in its hierarchy that implements this,

I don't think this is right. HTMLOptGroupElement, HTMLOptionElement, and SliderThumbElement overrides this.
Comment 3 Ryosuke Niwa 2021-02-02 22:09:43 PST
Comment on attachment 419105 [details]
Patch

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

>> Source/WebCore/ChangeLog:9
>> +        HTMLFormControlElement is the only class in its hierarchy that implements this,
> 
> I don't think this is right. HTMLOptGroupElement, HTMLOptionElement, and SliderThumbElement overrides this.

Nvm.
Comment 4 EWS 2021-02-02 23:14:30 PST
Committed r272299: <https://trac.webkit.org/changeset/272299>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 419105 [details].
Comment 5 Radar WebKit Bug Importer 2021-02-02 23:15:19 PST
<rdar://problem/73917813>
Comment 6 Darin Adler 2021-02-03 18:16:53 PST
Comment on attachment 419105 [details]
Patch

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

> Source/WebCore/html/HTMLFormControlElement.h:116
> +    bool isDisabledOrReadOnly() const { return m_disabled || m_disabledByAncestorFieldset || m_isReadOnly; }

Can this optimization be done by adding final somewhere instead?
Comment 7 Darin Adler 2021-02-03 18:19:38 PST
Comment on attachment 419105 [details]
Patch

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

>> Source/WebCore/html/HTMLFormControlElement.h:116
>> +    bool isDisabledOrReadOnly() const { return m_disabled || m_disabledByAncestorFieldset || m_isReadOnly; }
> 
> Can this optimization be done by adding final somewhere instead?

I don’t get it — given that classes override isDisabledFormControl, is this change correct?
Comment 8 Simon Fraser (smfr) 2021-02-03 19:21:16 PST
(In reply to Darin Adler from comment #7)
> Comment on attachment 419105 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=419105&action=review
> 
> >> Source/WebCore/html/HTMLFormControlElement.h:116
> >> +    bool isDisabledOrReadOnly() const { return m_disabled || m_disabledByAncestorFieldset || m_isReadOnly; }
> > 
> > Can this optimization be done by adding final somewhere instead?
> 
> I don’t get it — given that classes override isDisabledFormControl, is this
> change correct?

None of the classes that override isDisabledFormControl() are HTMLFormControlElement subclasses.

Would marking HTMLFormControlElement::isDisabledFormControl() final be equivalent? I'm not sure what compiler optimizations are enabled by 'final'.
Comment 9 Ryosuke Niwa 2021-02-03 21:37:07 PST
(In reply to Simon Fraser (smfr) from comment #8)
> (In reply to Darin Adler from comment #7)
> > Comment on attachment 419105 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=419105&action=review
> > 
> > >> Source/WebCore/html/HTMLFormControlElement.h:116
> > >> +    bool isDisabledOrReadOnly() const { return m_disabled || m_disabledByAncestorFieldset || m_isReadOnly; }
> > > 
> > > Can this optimization be done by adding final somewhere instead?
> > 
> > I don’t get it — given that classes override isDisabledFormControl, is this
> > change correct?
> 
> None of the classes that override isDisabledFormControl() are
> HTMLFormControlElement subclasses.
> 
> Would marking HTMLFormControlElement::isDisabledFormControl() final be
> equivalent? I'm not sure what compiler optimizations are enabled by 'final'.

It'd avoid stable pointer lookup!
Comment 10 Darin Adler 2021-02-04 10:03:58 PST
(In reply to Simon Fraser (smfr) from comment #8)
> Would marking HTMLFormControlElement::isDisabledFormControl() final be
> equivalent? I'm not sure what compiler optimizations are enabled by 'final'.

Yes, I think it would be equivalent, as long as the implementation of isDisabledFormControl was in the header. The combination of final and inlining should do exactly the same as this change. And the bonus is that it would optimize any other similar call sites in the same way.
Comment 11 Darin Adler 2021-02-04 10:05:13 PST
(In reply to Ryosuke Niwa from comment #9)
> It'd avoid stable pointer lookup!

Ryosuke means "vtable pointer lookup". Basically, if we didn’t inline, then the function would be faster, and who knows how good the link time optimization is at giving the same benefits as inlining. But, as I said, with inlining it should literally be the same.
Comment 12 Ryosuke Niwa 2021-03-05 00:44:18 PST
(In reply to Darin Adler from comment #11)
> (In reply to Ryosuke Niwa from comment #9)
> > It'd avoid stable pointer lookup!
> 
> Ryosuke means "vtable pointer lookup". Basically, if we didn’t inline, then
> the function would be faster, and who knows how good the link time
> optimization is at giving the same benefits as inlining. But, as I said,
> with inlining it should literally be the same.

Addressing this in https://bugs.webkit.org/show_bug.cgi?id=222783