Skip to content

perf: update periodic panel text without replacing child nodes - #350

Merged
jackhai9 merged 1 commit into
mainfrom
perf/text-node-writes
Nov 10, 2026
Merged

jackhai9 merged 1 commit into
mainfrom
perf/text-node-writes

Conversation

@jackhai9

Copy link
Copy Markdown
Owner

Problem

On logged-in Binance futures pages, Binance's price-alert CSS rule .price-alert-modal :has(>div.bn-skeleton)>:not(.bn-skeleton) makes every "remove all children" write (assigning textContent/innerHTML, replaceChildren on an element with children) trigger a whole-body style recalculation (~45–60 ms over ~14k elements).

  • 6 s trace during a continuous close: 1476 of 1540 ms of style recalcs came from 44 whole-body recalcs.
  • Live A/B removing only that rule (restored byte-identically): 0 whole-body recalcs, 66 ms vs 437 ms.
  • While idle, all 31/31 triggers came from these userscripts (Strategy 29 renderStatus, trading-data updateFooter, CMC, orderbook setLadderStatus).
  • Patching Binance's stylesheet was rejected: adding crossorigin breaks the whole chunk CSS for browsers with an existing no-cors cache entry (CDN omits ACAO and Vary: Origin without an Origin header).

Change

  • src/shared/dom-text.js setElementText: update the single existing Text node's data; unchanged values are not written.
  • Orderbook 2.7.248: status line, rebalance status, cancel button, quantity labels, side buttons, hint, depth-profile toggle/status.
  • Trading data 1.2.8: one-second footer clock and funding cells.
  • Strategy 29 0.5.18: all dynamic summary text; unit and recent-signal rows rebuild only when their rendered content changes.
  • CoinMarketCap panel unchanged (30 s refresh always changes the fetch time; rebuild happens in one task).
  • Docs: shared contract in docs/userscript-validation.md.

Validation

  • New MutationObserver tests require characterData-only changes (orderbook ladder status e2e, trading-data panel, Strategy 29 polls, helper unit tests); each fails on the previous code. A control test keeps real content changes rebuilding rows.
  • Verified in Chromium 151 that an element left with a zero-length Text node still matches :empty.
  • npm test 2666 passed; npm run test:ui 671 passed; builds, lint:tests, lint:ui-copy, check:binance-userscripts, check:binance-orderbook-trade, git diff --check pass. Generated versions match sources; CMC artifact unchanged.
  • Independent read-only review: ship with fixes; all findings addressed.
  • Not yet re-traced on the live page.

🤖 Generated with Claude Code

On logged-in Binance futures pages every write that removes all children of
an element (textContent/innerHTML assignment, replaceChildren) makes Chrome
re-evaluate :has() on its ancestors, and Binance's price-alert rule
`.price-alert-modal :has(>div.bn-skeleton)>:not(.bn-skeleton)` turns that into
a whole-body style recalculation (~45-60 ms over ~14k elements). A 6 s trace
during a continuous close spent 1476 of 1540 ms of style recalcs in 44 such
recalcs; a live A/B removing only that rule removed all of them. While idle,
every trigger came from these userscripts.

Add setElementText (src/shared/dom-text.js), which updates the existing Text
node's data instead:
- orderbook 2.7.248: status line, rebalance status, cancel button, quantity
  labels, side buttons, hint, depth-profile toggle/status;
- trading-data 1.2.8: one-second footer clock and funding cells;
- Strategy 29 0.5.18: all dynamic summary text, and unit/signal rows rebuild
  only when their rendered content changes.
The CoinMarketCap panel is unchanged: its 30 s refresh always changes the
fetch time and rebuilds in one task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jackhai9
jackhai9 merged commit 72ef47b into main Nov 10, 2026
3 checks passed
@jackhai9
jackhai9 deleted the perf/text-node-writes branch November 10, 2026 23:09
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