perf(render): clear the render area with replaceChildren() - #4936
Draft
lukecotter wants to merge 1 commit into
Draft
perf(render): clear the render area with replaceChildren()#4936lukecotter wants to merge 1 commit into
lukecotter wants to merge 1 commit into
Conversation
Replace the `while(element.firstChild) removeChild(...)` loops in VirtualDomVertical.clearRows / _virtualRenderFill and BasicVertical.clearRows with a single native element.replaceChildren() call, avoiding N individual DOM mutations per clear.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Replace the three
while(element.firstChild) element.removeChild(element.firstChild)loops — in
VirtualDomVertical.clearRows,VirtualDomVertical._virtualRenderFillandBasicVertical.clearRows— with a single nativeelement.replaceChildren().Honest reporting of the measurement
The benchmark tier cannot see this change. Measured on its own build at 500k rows,
K=5, medians:
rerenderInPlacemetricThe granular-scroll and tree-rerender scenarios are identical to master on every
counter (s1Churn 240, s1Nodes 48, s1Batches 24; nodesCollapse/nodesExpand 120/120).
The reason is that the
nodescounter measures rows moved, andreplaceChildren()moves the same rows. The saving is in the number of native DOM calls, which no
counter in the harness reports, and
msClearat 11.0 → 11.4 with 15.7% relativestandard deviation is noise in both directions.
So the claim rests on
test/unit/core/VirtualDomVertical.clearRows.spec.jsand on thisbeing strictly fewer native calls for the same result. It is a call-count and clarity
change, not a measurable speed-up. Draft because it is part of a larger renderer
series; happy for it to be judged on that basis alone.
Note
The companion virtual-renderer rewrite PR in this series also uses
replaceChildren()in
VirtualDomVertical, so expect a conflict there. Only theBasicVertical.jschangeis unique to this PR.