Bug 224589 - Avoid indirect load in ContainerNode::hasOneChild()
Summary: Avoid indirect load in ContainerNode::hasOneChild()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-14 19:16 PDT by Ryosuke Niwa
Modified: 2021-04-14 20:35 PDT (History)
7 users (show)

See Also:


Attachments
Patch (1.62 KB, patch)
2021-04-14 19:43 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>