WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
228541
ListAttributeTargetObserver is needlessly created even when there is no list attribute
https://bugs.webkit.org/show_bug.cgi?id=228541
Summary
ListAttributeTargetObserver is needlessly created even when there is no list ...
Maciej Stachowiak
Reported
2021-07-28 00:47:47 PDT
ListAttributeTargetObserver is needlessly created even when there is no list attribute
Attachments
Patch
(1.77 KB, patch)
2021-07-28 00:51 PDT
,
Maciej Stachowiak
no flags
Details
Formatted Diff
Diff
Patch
(2.04 KB, patch)
2021-07-31 14:13 PDT
,
Maciej Stachowiak
no flags
Details
Formatted Diff
Diff
Patch
(2.04 KB, patch)
2021-07-31 14:17 PDT
,
Maciej Stachowiak
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Maciej Stachowiak
Comment 1
2021-07-28 00:51:55 PDT
Created
attachment 434410
[details]
Patch
Maciej Stachowiak
Comment 2
2021-07-28 00:52:38 PDT
Patch is for EWS only.
Darin Adler
Comment 3
2021-07-28 10:20:39 PDT
Comment on
attachment 434410
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=434410&action=review
> Source/WebCore/html/HTMLInputElement.cpp:1686 > + const AtomString& listAttrValue = attributeWithoutSynchronization(listAttr); > + if (!listAttrValue.isNull() && isConnected())
Could put this all inside the if and use auto: if (auto& value = attributeWithoutSynchronization(listAttr); !value.isNull() && isConnected()) But also, if the element is not connected, why fetch the attribute at all?
Maciej Stachowiak
Comment 4
2021-07-28 10:34:51 PDT
Comment on
attachment 434410
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=434410&action=review
>> Source/WebCore/html/HTMLInputElement.cpp:1686 >> + if (!listAttrValue.isNull() && isConnected()) > > Could put this all inside the if and use auto: > > if (auto& value = attributeWithoutSynchronization(listAttr); !value.isNull() && isConnected()) > > But also, if the element is not connected, why fetch the attribute at all?
If that's the currently more preferred style, I can make those first two changes. Checkin isConnected seems like it could be faster than an attribute fetch, but I think I'd have to use nested ifs to both avoid the attribute fetch for disconnected elements and avoid double hash lookup when the list attribute is actually present. Worth it?
Darin Adler
Comment 5
2021-07-28 11:42:01 PDT
Comment on
attachment 434410
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=434410&action=review
>>> Source/WebCore/html/HTMLInputElement.cpp:1686 >>> + if (!listAttrValue.isNull() && isConnected()) >> >> Could put this all inside the if and use auto: >> >> if (auto& value = attributeWithoutSynchronization(listAttr); !value.isNull() && isConnected()) >> >> But also, if the element is not connected, why fetch the attribute at all? > > If that's the currently more preferred style, I can make those first two changes. > > Checkin isConnected seems like it could be faster than an attribute fetch, but I think I'd have to use nested ifs to both avoid the attribute fetch for disconnected elements and avoid double hash lookup when the list attribute is actually present. Worth it?
Yes, I think we’re getting good results from scoping things using this new style. I personally think it would be worth the nested if, but it’s a close call. Not a real performance tradeoff I guess because one more hash table lookup isn’t huge given how rarely this function would be called. Sadly when the attribute itself changes, the attributeWithoutSynchronization(listAttr) call isn’t needed.
Darin Adler
Comment 6
2021-07-28 12:42:15 PDT
To be clear on that last point, there are really three callers here, one where the attribute value changed, and two where the connectedness changed. Could save a hash table lookup in the case where the attribute value changed, because the caller already has the attribute value. But not sure that’s worth doing for such a micro-optimization.
Yusuke Suzuki
Comment 7
2021-07-28 16:27:39 PDT
Comment on
attachment 434410
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=434410&action=review
>>>> Source/WebCore/html/HTMLInputElement.cpp:1686 >>>> + if (!listAttrValue.isNull() && isConnected()) >>> >>> Could put this all inside the if and use auto: >>> >>> if (auto& value = attributeWithoutSynchronization(listAttr); !value.isNull() && isConnected()) >>> >>> But also, if the element is not connected, why fetch the attribute at all? >> >> If that's the currently more preferred style, I can make those first two changes. >> >> Checkin isConnected seems like it could be faster than an attribute fetch, but I think I'd have to use nested ifs to both avoid the attribute fetch for disconnected elements and avoid double hash lookup when the list attribute is actually present. Worth it? > > Yes, I think we’re getting good results from scoping things using this new style. > > I personally think it would be worth the nested if, but it’s a close call. Not a real performance tradeoff I guess because one more hash table lookup isn’t huge given how rarely this function would be called. Sadly when the attribute itself changes, the attributeWithoutSynchronization(listAttr) call isn’t needed.
I think hashtable lookup is not free, so if we can avoid, then we should. :) In this case, isConnected() is just a bit check, so the following looks better to me. if (isConnected()) { if (const AtomString& listAttrValue = attributeWithoutSynchronization(listAttr); !listAttrValue.isNull()) m_listAttributeTargetObserver = makeUnique<ListAttributeTargetObserver>(listAttrValue, this); }
Maciej Stachowiak
Comment 8
2021-07-31 14:13:41 PDT
Created
attachment 434706
[details]
Patch
Maciej Stachowiak
Comment 9
2021-07-31 14:17:13 PDT
Created
attachment 434707
[details]
Patch
Maciej Stachowiak
Comment 10
2021-07-31 14:19:39 PDT
I made the changes suggested by Darin and Yusuke. I'm not sure it's more readable to have the declaration inside the if. This first version seems harder to follow: if (isConnected()) { if (auto& listAttrValue = attributeWithoutSynchronization(listAttr); !listAttrValue.isNull()) m_listAttributeTargetObserver = makeUnique<ListAttributeTargetObserver>(listAttrValue, this); } This seems easier; one extra line, but it's easier to see wha the actual if condition is. if (isConnected()) { auto& listAttrValue = attributeWithoutSynchronization(listAttr); if (!listAttrValue.isNull()) m_listAttributeTargetObserver = makeUnique<ListAttributeTargetObserver>(listAttrValue, this); } I'm happy to commit either way though. I posted the first version for review.
Yusuke Suzuki
Comment 11
2021-07-31 15:13:58 PDT
Comment on
attachment 434707
[details]
Patch r=me
EWS
Comment 12
2021-07-31 15:48:26 PDT
Committed
r280521
(
240153@main
): <
https://commits.webkit.org/240153@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 434707
[details]
.
Radar WebKit Bug Importer
Comment 13
2021-07-31 15:49:15 PDT
<
rdar://problem/81370699
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug