Skip to content

perf(render): clear the render area with replaceChildren() - #4936

Draft
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf/render-replace-children
Draft

perf(render): clear the render area with replaceChildren()#4936
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf/render-replace-children

Conversation

@lukecotter

Copy link
Copy Markdown
Contributor

Change

Replace the three while(element.firstChild) element.removeChild(element.firstChild)
loops — in VirtualDomVertical.clearRows, VirtualDomVertical._virtualRenderFill and
BasicVertical.clearRows — with a single native element.replaceChildren().

Honest reporting of the measurement

The benchmark tier cannot see this change. Measured on its own build at 500k rows,
K=5, medians:

rerenderInPlace metric Before After
msFilter 19.7 18.7
nodesFilter 60 60
msClear 11.0 11.4 (sdPct 15.7)
nodesClear 80 80
msReplace 115.9 118.3
nodesReplace 160 160

The 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 nodes counter measures rows moved, and replaceChildren()
moves the same rows. The saving is in the number of native DOM calls, which no
counter in the harness reports, and msClear at 11.0 → 11.4 with 15.7% relative
standard deviation is noise in both directions.

So the claim rests on test/unit/core/VirtualDomVertical.clearRows.spec.js and on this
being 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 the BasicVertical.js change
is unique to this PR.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant