Skip to content

BUILD-1297: skip unchanged viewer HUD updates - #5283

Open
TG0000 wants to merge 2 commits into
ItsNotRexed:mainfrom
TG0000:perf/viewer-hud-updates
Open

TG0000 wants to merge 2 commits into
ItsNotRexed:mainfrom
TG0000:perf/viewer-hud-updates

Conversation

@TG0000

@TG0000 TG0000 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changes

The viewer builds the HUD text from the same frame data and only replaces the DOM when the displayed markup changes. Camera movement, streaming, rendering and the FPS counter still run every frame.

BUILD-1297 — claimed in coordination and carried forward to #5256. Independent of navigation PRs #3598 and #3687. If either lands first, the adjacent HUD change for the movement label may need a small rebase.

Validation

  • 51/51 passed in node --test tests/test_viewer_streaming.cjs after locally merging with current main.
  • The actual animation callback ran with a real DOM in Chrome 158 on Windows 11 / Ryzen 9 5900X. The stationary workload went from 600 HUD replacements to 0 per 600 frames and from 40.55 to 2.45 ms median per block. Slow movement went from 600 to 31 replacements and from 38.95 to 3.70 ms. Mixed loading, errors and render counters went from 600 to 24 replacements and from 43.10 to 4.40 ms. These timings cover the isolated callback with fixture data and stubbed rendering.
  • Compared the exact HUD markup over the same 200-frame trace and verified that streaming and rendering were invoked every frame. Checked the initial test-terrain banner and the CSS warning color.

AI-assisted (OpenAI Codex). Synthetic viewer state. CPU-backed callback benchmark.

Depends on: #3598, #3687

These are viewer HUD merge overlaps. Retain the movement label in the cached markup if either navigation PR lands before this one.

Current head dc12c72c includes a dedicated regression test for suppressed duplicate HUD writes. The local integration with main passed 52 tests.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 15eeaf1 a 160-frame CPU trace through the production callback yielded identical HUD markup on every frame. DOM assignments fell from 160 to 13, one initial assignment and one per visible change. Streaming and rendering each ran 160 times on both revisions. When integrating #3598 or #3687, retain the movement label in nextHud so a movement-mode change at a fixed position refreshes the display. That integration note comes from source inspection. AI-assisted.

@King1565

Copy link
Copy Markdown

Tested 15eeaf1 on Linux, Node v22.23.5 (CPU only, no GPU, no game files): pass with notes

Ran

  • node --test tests/test_viewer_streaming.cjs: head 47/47, head merged onto current main 51/51, main 51/51.
  • git diff --check: clean.
  • A scratch script ran the real index.html animation callback, using the test file's vm harness with a counting #hud. Results: one write on the first frame, 0 writes per 100 still frames once fps settles (main: 100), a write when draw calls change, none for a move under 0.05 m, one for a NaN position and none after it.

Read

  • Merges cleanly with current main. Main has not changed the HUD code since the merge-base.
  • No defect found. The cache key is the full rendered string, so every field shown is compared. "" makes the first frame always write, "NaN" === "NaN" holds, and this loop is the only writer to #hud.
  • Note: no test covers the HUD path. A small test that counts innerHTML writes over still and changing frames would lock this in.

AI-assisted (Claude Code).

@TimIdle

TimIdle commented Nov 23, 2026

Copy link
Copy Markdown

Windows test result for head 15eeaf1.

Windows 11 Home (10.0.26300), Node v24.21.0, CPython 3.14.10, CPU only, no game files.

  • node --test tests/test_viewer_streaming.cjs: tests 47, pass 47, fail 0
  • python -I tests/test_docs_links.py: OK
  • python -I tests/test_text_encoding.py: OK

AI-assisted (Claude Code)

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 15eeaf1 on Windows Server 2022, CPython 3.13.12: pass

  • node tests/test_viewer_streaming.cjs -> pass 51, fail 0 (Node v24.22.2)
  • viewer/index.html-only change; existing suite passes - no dedicated test for the new lines.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — #5283 @ 15eeaf1

Diff: viewer/index.html only. Caches the HUD markup in lastHud and skips the hud.innerHTML write when it is unchanged; all per-frame state still updates.

Tested:

  • node --test tests/test_viewer_streaming.cjs → 47 passed, 0 failed (PR head).
  • After git merge origin/main (merge 98bf56202): same command → 51 passed, 0 failed.
  • git diff --check → clean.

Verdict: PASS. No automated test exercises the skip itself, so the suite only proves no regression; the body's Chrome benchmark is the direct evidence. Adjacent HUD work in #3598/#3687 may need a rebase, as noted; no blocker here.

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the coverage suggestion. dc12c72 adds a test that runs the production frame callback and counts DOM writes. It verifies the initial HUD, FPS stabilization, unchanged and sub-rounding frames, visible position and draw-count changes, and one stream/render call per frame. 48/48 pass on the branch and 52/52 after integration with current main. The test fails on the old unconditional write (9 writes vs 2). AI-assisted (OpenAI Codex).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested dc12c72c merged onto main 3faac557 on macOS, Apple M4, Node v26.13.0: pass. The earlier runs above were on 15eeaf1a, before the new test.

  • node --test tests/test_viewer_streaming.cjs: 52/52 pass; main gives 51/51.
  • The cache can't go stale: the frame callback is the only writer of the HUD element. In the merged tree, viewer/index.html:412 gets the element and :433-436 is its one innerHTML assignment. Nothing else writes hud.innerHTML.
  • Mutations: the new test catches all 3 I tried:
    • writing innerHTML on every frame;
    • never updating lastHud;
    • comparing against the initial "" instead of the last markup.
  • git diff --check: clean.

AI-assisted.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted Windows integration check for dc12c72c, Node 24.16.0. Tested with the local preview equivalents of #5244 (distant view range) and #5387 (elapsed-frame FPS). The author’s HUD test needed camera and fog defaults because the other layer uses them in the same callback. All assertions were preserved. The combined tree a05b7d25 passed 59 streaming tests and 10 asset tests.

A separate synthetic trace flipped between cached LOD tiers while keeping the displayed position and HUD markup unchanged. The camera and fog ranges still responded and the HUD made no writes. Displayed FPS and rounded position changes each triggered exactly one write. Bypassing the guard in memory produced two extra writes at the cached LOD switch. This checks behavior across the three patches; it does not measure browser speed.

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.

8 participants