[PR #3113] [MERGED] chore(client): per-surface + re-render-reason probes for #3104 #5802

Closed
opened 2026-10-22 04:19:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3113
Author: @kolacheee
Created: 6/30/2026
Status: ✅ Merged
Merged: 7/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: chore/3104-chat-surface-section-timers


📝 Commits (5)

  • c2a9291 chore(client): add per-surface render probes for #3104
  • 6340641 chore(client): add re-render-reason probe for #3104
  • 6347970 Merge branch 'staging' into chore/3104-chat-surface-section-timers
  • f6057c4 fix(client): remove invalid chat area perf probes
  • 743e935 fix(client): lazily build chat area perf snapshot

📊 Changes

9 files changed (+101 additions, -2 deletions)

View changed files

📝 packages/client/src/components/chat/ChatArea.tsx (+27 -1)
📝 packages/client/src/components/chat/ChatConversationSurface.tsx (+2 -0)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+2 -0)
📝 packages/client/src/components/chat/ConversationView.tsx (+2 -0)
📝 packages/client/src/components/game/GameCombatUI.tsx (+2 -0)
📝 packages/client/src/components/game/GameNarration.tsx (+2 -0)
📝 packages/client/src/components/game/GameSurface.tsx (+2 -0)
📝 packages/client/src/components/game/GameWidgetPanel.tsx (+2 -0)
📝 packages/client/src/lib/perf-diagnostics.ts (+60 -1)

📄 Description

Linked issue

Relates to #3104 — this PR adds diagnostics to localize the freeze; it does not fix or close it. Builds on the merged #3111 (the opt-in render-timing tool) and is complementary to #3112 (the tracker-panel fix, which the logs show does not address #3104 — see below).

Why this change

#3111 added an opt-in render timer that proved the #3104 freeze lives in the chat-area subtree — but that isn't specific enough to fix against. Affected-user logs since then show two things:

User / mode chat-area render+commit tracker-panel Active surface
Game 7,000–10,000 ms (one 41 s long task) never slow GameSurface
Roleplay 22,000–24,500 ms 0–8 ms ChatRoleplaySurface
Game (milder) 660–1,350 ms, repeated n/a GameSurface
  1. The cost is the active message surface's render+commit, cross-mode — not GameSurface-specific.
  2. tracker-panel is consistently fast (0–8 ms), so #3112's tracker fix doesn't resolve #3104.

This PR adds two layers of probe so an affected user's console names both where the cost is and why the surface re-renders:

  • Per-surface timers — drill one level under chat-area to the exact slow subtree per mode.
  • Re-render-reason probe (useWhyRender on ChatArea) — on each render, log which source input changed, and tag renders with no recent user input as IDLE (an idle re-render storm is a loop, not interaction cost). This targets the re-render storm — the repeated full-subtree renders that turn one slow render into a freeze.

What changed

Reuses the existing lib/perf-diagnostics.ts tool (no new opt-in mechanism — same localStorage.mariPerfVerbose="1" flag, off by default).

Per-surface render timers (one useRenderTimer per component; fires once per render, never per message):

  • Game: game-surface, game-narration (un-virtualized VN history, prime suspect), game-hud (world-state / tracker widgets named in #3104), game-combat.
  • Roleplay: rp-surface (its message map is inline JSX, so the surface root is also the list boundary).
  • Conversation: convo-surface (shell) + convo-messages (ConversationView, the heavy list).

Re-render-reason probe (useWhyRender, new in perf-diagnostics.ts, wired into ChatArea): logs … why-render #N — changed: <inputs> (or no watched input changed = re-render from the parent), with an IDLE tag when no pointer/key/wheel/touch happened in the last second. Watches ChatArea's source inputs (store slices, query results, characterMap, the presence clock, agent state).

Per-message leaf components (ChatMessage, ConversationMessage) are deliberately not probed (they'd log once per message and flood the console). Lower-suspicion game sub-sections (weather / map / party / inventory / mobile HUD) are left out to stay focused; each is a one-line follow-up.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Done by the agent (not a substitute for human verification):

  • pnpm check → exit 0 (TypeScript + ESLint + client build all clean), run twice (once per commit).

Still needs manual verification in a real built install:

  • With no flag set: confirm zero [mari-perf] console output and no behavior change in game / roleplay / conversation chats (probes must be fully inert by default).
  • Run localStorage.mariPerfVerbose = "1", reload, open a chat in each mode: confirm the surface labels appear with small ms on a normal chat, and that chat-area why-render #N — changed: … lines appear on interaction.
  • Have an affected user (long, agent-heavy pre-2.0.8 chat) reproduce the freeze with the flag on and capture both the SLOW <label> render+commit <N>ms line and the why-render … changed: … / IDLE lines — together these name the slow subtree and its re-render trigger.
  • Confirm light/dark mode and mobile viewport are unaffected (no UI/DOM change).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No UI change — measurement only (the probes add no DOM and produce no output unless the opt-in flag is set).

Summary by CodeRabbit

  • New Features
    • Added optional render-diagnostics for chat, game, and conversation screens to help identify unnecessary re-renders.
    • Added a new opt-in “why did this render” check that highlights which visible inputs changed and can flag idle re-render loops.
    • Diagnostic output remains off by default and only appears when verbose performance logging is enabled.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3113 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/30/2026 **Status:** ✅ Merged **Merged:** 7/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `chore/3104-chat-surface-section-timers` --- ### 📝 Commits (5) - [`c2a9291`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2a92916ff2a8d845e2268cab726e5aa878ebf80) chore(client): add per-surface render probes for #3104 - [`6340641`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6340641d1e76b726dc01c25ed29fb8a7e5be7708) chore(client): add re-render-reason probe for #3104 - [`6347970`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6347970a15bbff9dec99439b7c21c5a1d659db52) Merge branch 'staging' into chore/3104-chat-surface-section-timers - [`f6057c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f6057c46679434ff73ea4a6a1ba0e2b15b184580) fix(client): remove invalid chat area perf probes - [`743e935`](https://github.com/Pasta-Devs/Marinara-Engine/commit/743e9350831eec992db5b22c19492fb37302ff92) fix(client): lazily build chat area perf snapshot ### 📊 Changes **9 files changed** (+101 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatArea.tsx` (+27 -1) 📝 `packages/client/src/components/chat/ChatConversationSurface.tsx` (+2 -0) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+2 -0) 📝 `packages/client/src/components/chat/ConversationView.tsx` (+2 -0) 📝 `packages/client/src/components/game/GameCombatUI.tsx` (+2 -0) 📝 `packages/client/src/components/game/GameNarration.tsx` (+2 -0) 📝 `packages/client/src/components/game/GameSurface.tsx` (+2 -0) 📝 `packages/client/src/components/game/GameWidgetPanel.tsx` (+2 -0) 📝 `packages/client/src/lib/perf-diagnostics.ts` (+60 -1) </details> ### 📄 Description ## Linked issue Relates to #3104 — this PR adds **diagnostics to localize** the freeze; it does **not** fix or close it. Builds on the merged #3111 (the opt-in render-timing tool) and is complementary to #3112 (the tracker-panel fix, which the logs show does not address #3104 — see below). ## Why this change #3111 added an opt-in render timer that proved the #3104 freeze lives in the `chat-area` subtree — but that isn't specific enough to fix against. Affected-user logs since then show two things: | User / mode | `chat-area` render+commit | `tracker-panel` | Active surface | | --- | --- | --- | --- | | Game | 7,000–10,000 ms (one 41 s long task) | never slow | GameSurface | | Roleplay | 22,000–24,500 ms | 0–8 ms | ChatRoleplaySurface | | Game (milder) | 660–1,350 ms, repeated | n/a | GameSurface | 1. The cost is the **active message surface's render+commit**, **cross-mode** — not GameSurface-specific. 2. `tracker-panel` is consistently fast (0–8 ms), so #3112's tracker fix doesn't resolve #3104. This PR adds two layers of probe so an affected user's console names both **where** the cost is and **why** the surface re-renders: - **Per-surface timers** — drill one level under `chat-area` to the exact slow subtree per mode. - **Re-render-reason probe** (`useWhyRender` on ChatArea) — on each render, log *which source input changed*, and tag renders with no recent user input as `IDLE` (an idle re-render storm is a loop, not interaction cost). This targets the *re-render storm* — the repeated full-subtree renders that turn one slow render into a freeze. ## What changed Reuses the existing `lib/perf-diagnostics.ts` tool (no new opt-in mechanism — same `localStorage.mariPerfVerbose="1"` flag, off by default). **Per-surface render timers** (one `useRenderTimer` per component; fires once per render, never per message): - Game: `game-surface`, `game-narration` (un-virtualized VN history, prime suspect), `game-hud` (world-state / tracker widgets named in #3104), `game-combat`. - Roleplay: `rp-surface` (its message map is inline JSX, so the surface root is also the list boundary). - Conversation: `convo-surface` (shell) + `convo-messages` (ConversationView, the heavy list). **Re-render-reason probe** (`useWhyRender`, new in `perf-diagnostics.ts`, wired into ChatArea): logs `… why-render #N — changed: <inputs>` (or `no watched input changed` = re-render from the parent), with an `IDLE` tag when no pointer/key/wheel/touch happened in the last second. Watches ChatArea's source inputs (store slices, query results, `characterMap`, the presence clock, agent state). Per-message leaf components (`ChatMessage`, `ConversationMessage`) are deliberately **not** probed (they'd log once per message and flood the console). Lower-suspicion game sub-sections (weather / map / party / inventory / mobile HUD) are left out to stay focused; each is a one-line follow-up. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Done by the agent (not a substitute for human verification): - `pnpm check` → exit 0 (TypeScript + ESLint + client build all clean), run twice (once per commit). Still needs manual verification in a real built install: - With **no** flag set: confirm **zero** `[mari-perf]` console output and no behavior change in game / roleplay / conversation chats (probes must be fully inert by default). - Run `localStorage.mariPerfVerbose = "1"`, reload, open a chat in each mode: confirm the surface labels appear with small ms on a normal chat, and that `chat-area why-render #N — changed: …` lines appear on interaction. - Have an affected user (long, agent-heavy pre-2.0.8 chat) reproduce the freeze with the flag on and capture both the `SLOW <label> render+commit <N>ms` line **and** the `why-render … changed: …` / `IDLE` lines — together these name the slow subtree *and* its re-render trigger. - Confirm light/dark mode and mobile viewport are unaffected (no UI/DOM change). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No UI change — measurement only (the probes add no DOM and produce no output unless the opt-in flag is set). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added optional render-diagnostics for chat, game, and conversation screens to help identify unnecessary re-renders. * Added a new opt-in “why did this render” check that highlights which visible inputs changed and can flag idle re-render loops. * Diagnostic output remains off by default and only appears when verbose performance logging is enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:19:39 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5802
No description provided.