Problem
Node.appendChild(DocumentFragment) currently transfers children one at a time and recascades both the child subtree and parent after every transfer. Structural selectors therefore see transient sibling lists, so earlier children can retain incorrect :last-child, :nth-child, :first-child, :empty, and :has() results. The repeated parent traversal is also a hot path when Code OSS constructs or replaces panels.
A focused regression produces widths [5px,5px,5px]; atomic attachment should produce [3px,4px,5px].
Proposed fix
Transfer the fragment's children first, recascade the connected parent subtree once against the completed tree, then activate stylesheets and enqueue resources. Keep a build-time control path so the old and new algorithms can be benchmarked from the same revision.
Acceptance gates
- Direct native structural-selector regression passes.
- WPT-style fragment attachment contract passes.
- A deterministic A-B-B-A benchmark demonstrates at least 10% median improvement.
- Full native/runtime and package CI remain green.
- Packaged Code OSS visual, editor, and performance gates show no regression.
Current evidence
Six-block A-B-B-A measurement with seven measured and two warm-up iterations per run:
- control median p50: 74.9825 ms
- candidate median p50: 66.9720 ms
- improvement: 10.683%
A cooler four-block run measured 42.360 ms to 35.724 ms, a 15.666% improvement. The candidate direct regression and WPT contract pass; the control fails both the exact selector result and the WPT assertion.
Problem
Node.appendChild(DocumentFragment)currently transfers children one at a time and recascades both the child subtree and parent after every transfer. Structural selectors therefore see transient sibling lists, so earlier children can retain incorrect:last-child,:nth-child,:first-child,:empty, and:has()results. The repeated parent traversal is also a hot path when Code OSS constructs or replaces panels.A focused regression produces widths
[5px,5px,5px]; atomic attachment should produce[3px,4px,5px].Proposed fix
Transfer the fragment's children first, recascade the connected parent subtree once against the completed tree, then activate stylesheets and enqueue resources. Keep a build-time control path so the old and new algorithms can be benchmarked from the same revision.
Acceptance gates
Current evidence
Six-block A-B-B-A measurement with seven measured and two warm-up iterations per run:
A cooler four-block run measured 42.360 ms to 35.724 ms, a 15.666% improvement. The candidate direct regression and WPT contract pass; the control fails both the exact selector result and the WPT assertion.