Bug 250654 - GraphicsLayer::removeAllChildren shouldn't be n^2
Summary: GraphicsLayer::removeAllChildren shouldn't be n^2
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Compositing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-01-15 13:16 PST by Ahmad Saleem
Modified: 2023-10-03 17:36 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2023-01-15 13:16:06 PST
Hi Team,

Usually reducing expensive calls are always better, so I just wanted to raise and get input whether we can do similar to improve performance or reach to similar idea:

Blink Commit - https://chromium.googlesource.com/chromium/blink/+/ea1156d6f005f978e4da707ef4e2060c2fc7151f

WebKit GitHub - https://searchfox.org/wubkat/source/Source/WebCore/platform/graphics/GraphicsLayer.cpp#316 & https://searchfox.org/wubkat/source/Source/WebCore/platform/graphics/GraphicsLayer.cpp#395

Just wanted to raise so if it is something worth implementing with the same idea, we can gain some performance point.

Thanks!
Comment 1 Radar WebKit Bug Importer 2023-01-22 13:17:18 PST
<rdar://problem/104534645>
Comment 2 Ahmad Saleem 2023-07-24 13:19:34 PDT
This compiles:

void GraphicsLayer::removeAllChildren()
{
    while (!m_children.isEmpty()) {
        auto curLayer = m_children.last();

...


_______________

NOTE - It seems 'removeFromParent' calls 'removeFromParentInternal()' and it seems to be using 'removeFirstMatching' rather than 'reverseFind' but don't know how to amend this part.


void GraphicsLayer::removeFromParentInternal()
{
    if (m_parent) {
        GraphicsLayer* parent = m_parent;
        setParent(nullptr);
        parent->m_children.removeFirstMatching([this](auto& layer) {
            return layer.ptr() == this;
        });
        // |this| may be destroyed here.
    }
}

______________
Comment 3 Chris Dumez 2023-10-03 14:23:42 PDT
Pull request: https://github.com/WebKit/WebKit/pull/18578
Comment 4 EWS 2023-10-03 17:36:06 PDT
Committed 268814@main (106c4aae5f43): <https://commits.webkit.org/268814@main>

Reviewed commits have been landed. Closing PR #18578 and removing active labels.