Skip to content

Web Inspector: [SI] DOMManager rescans every DOM node for each pending frame document when splicing#69441

Draft
Ahmad-S792 wants to merge 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/Web-Inspector-DOMManager-rescans-every-DOM-node-for-each-pending-frame-document-when-splicing
Draft

Web Inspector: [SI] DOMManager rescans every DOM node for each pending frame document when splicing#69441
Ahmad-S792 wants to merge 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/Web-Inspector-DOMManager-rescans-every-DOM-node-for-each-pending-frame-document-when-splicing

Conversation

@Ahmad-S792

@Ahmad-S792 Ahmad-S792 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

c009a18

Web Inspector: [SI] DOMManager rescans every DOM node for each pending frame document when splicing
https://bugs.webkit.org/show_bug.cgi?id=319454
rdar://182266167

Reviewed by NOBODY (OOPS!).

When a cross-origin frame document arrives before its owning iframe element is known,
it is queued and re-tried later. _trySpliceUnsplicedFrameDocuments() ran that retry by
calling _trySpliceFrameDocumentIntoNode() once per pending document, and each call
allocated a fresh Object.values(this._idToDOMNode) and linearly scanned every known DOM
node to find a matching iframe/frame element. It also constructed a new URL for the
frame document's URL on every candidate node. The result was O(pendingDocuments *
totalNodes) work with a per-document array allocation and redundant per-node URL parsing.

Collect the candidate iframe/frame elements once per pass in _unmatchedFrameNodes() and
reuse that list across all pending documents, and resolve the frame document's URL lazily
at most once per document. This lowers the cost to O(totalNodes + pendingDocuments *
frameElements) with no behavior change: an element matched by an earlier document in the
same pass is still skipped via its now-set contentDocument, so duplicate-URL documents and
already-populated iframes behave exactly as before.

Test: inspector/unit-tests/dom-frame-document-splice.html

* LayoutTests/inspector/unit-tests/dom-frame-document-splice-expected.txt: Added.
* LayoutTests/inspector/unit-tests/dom-frame-document-splice.html: Added.
* Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js:
(WI.DOMManager.prototype._unmatchedFrameNodes):
(WI.DOMManager.prototype._trySpliceFrameDocumentIntoNode):
(WI.DOMManager.prototype._trySpliceUnsplicedFrameDocuments):

c009a18

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ⏳ 🛠 win ✅ 🛠 ios-apple
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ⏳ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
loading 🧪 ios-wk2-wpt ⏳ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
loading 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
⏳ 🛠 ios-safer-cpp ⏳ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 vision-sim ⏳ 🧪 mac-intel-wk2 ⏳ 🛠 playstation
✅ 🧪 vision-wk2 ⏳ 🛠 mac-safer-cpp
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

…g frame document when splicing

https://bugs.webkit.org/show_bug.cgi?id=319454
rdar://182266167

Reviewed by NOBODY (OOPS!).

When a cross-origin frame document arrives before its owning iframe element is known,
it is queued and re-tried later. _trySpliceUnsplicedFrameDocuments() ran that retry by
calling _trySpliceFrameDocumentIntoNode() once per pending document, and each call
allocated a fresh Object.values(this._idToDOMNode) and linearly scanned every known DOM
node to find a matching iframe/frame element. It also constructed a new URL for the
frame document's URL on every candidate node. The result was O(pendingDocuments *
totalNodes) work with a per-document array allocation and redundant per-node URL parsing.

Collect the candidate iframe/frame elements once per pass in _unmatchedFrameNodes() and
reuse that list across all pending documents, and resolve the frame document's URL lazily
at most once per document. This lowers the cost to O(totalNodes + pendingDocuments *
frameElements) with no behavior change: an element matched by an earlier document in the
same pass is still skipped via its now-set contentDocument, so duplicate-URL documents and
already-populated iframes behave exactly as before.

Test: inspector/unit-tests/dom-frame-document-splice.html

* LayoutTests/inspector/unit-tests/dom-frame-document-splice-expected.txt: Added.
* LayoutTests/inspector/unit-tests/dom-frame-document-splice.html: Added.
* Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js:
(WI.DOMManager.prototype._unmatchedFrameNodes):
(WI.DOMManager.prototype._trySpliceFrameDocumentIntoNode):
(WI.DOMManager.prototype._trySpliceUnsplicedFrameDocuments):
@Ahmad-S792 Ahmad-S792 self-assigned this Jul 15, 2026
@Ahmad-S792 Ahmad-S792 added the Web Inspector Bugs related to the WebKit Web Inspector. label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Web Inspector Bugs related to the WebKit Web Inspector.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants