Bug 224589

Summary: Avoid indirect load in ContainerNode::hasOneChild()
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: DOMAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, darin, esprehn+autocc, ews-watchlist, kangil.han, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Ryosuke Niwa 2021-04-14 19:16:46 PDT
Getting nextSibling() will involve loading the first child into the register.
Avoid that and just check m_firstChild and m_lastChild instead to avoid this extra memory load.
Comment 1 Ryosuke Niwa 2021-04-14 19:43:00 PDT
Created attachment 426070 [details]
Patch
Comment 2 Chris Dumez 2021-04-14 19:47:33 PDT
Comment on attachment 426070 [details]
Patch

If you say this is more efficient, I believe you. R=me. The new code definitely still is correct.
Comment 3 Ryosuke Niwa 2021-04-14 19:52:44 PDT
(In reply to Chris Dumez from comment #2)
> Comment on attachment 426070 [details]
> Patch
> 
> If you say this is more efficient, I believe you. R=me. The new code
> definitely still is correct.

Yeah because m_firstChild and m_lastChild are both in the same object whereas m_firstChild isn't. CPU needs to load the content of m_firstChild and then retrieve m_nextSibling, which is an indirect load that CPU will have a hard time predicting so whilst prefetched would detect this and will fetch it, it can still result in either TLB hit miss and/or L2/L3 cache misses, which would be horrifyingly expensive.
Comment 4 Ryosuke Niwa 2021-04-14 20:34:17 PDT
Comment on attachment 426070 [details]
Patch

Clearing flags on attachment: 426070

Committed r275997 (236549@main): <https://commits.webkit.org/236549@main>
Comment 5 Ryosuke Niwa 2021-04-14 20:34:19 PDT
All reviewed patches have been landed.  Closing bug.
Comment 6 Radar WebKit Bug Importer 2021-04-14 20:35:15 PDT
<rdar://problem/76682121>